-
Notifications
You must be signed in to change notification settings - Fork 1
/
login.go
144 lines (115 loc) · 3.12 KB
/
login.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// Golang port of Overleaf
// Copyright (C) 2021-2022 Jakob Ackermann <das7pad@outlook.com>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package types
import (
"strings"
"github.com/das7pad/overleaf-go/pkg/asyncForm"
"github.com/das7pad/overleaf-go/pkg/errors"
"github.com/das7pad/overleaf-go/pkg/sharedTypes"
"github.com/das7pad/overleaf-go/pkg/templates"
)
type LogoutRequest struct {
WithSession
}
type LogoutResponse = asyncForm.Response
type LogoutPageRequest struct {
WithSession
}
type LogoutPageResponse struct {
Data *templates.UserLogoutData
}
type UserPassword string
func (p UserPassword) Validate() error {
if len(p) < 6 {
return &errors.ValidationError{Msg: "password too short, min 6"}
}
if len(p) > 72 {
return &errors.ValidationError{Msg: "password too long, max 72"}
}
return nil
}
func (p UserPassword) CheckForEmailMatch(email sharedTypes.Email) error {
if strings.Contains(strings.ToLower(string(p)), email.LocalPart()) {
return &errors.ValidationError{Msg: "password contain email part"}
}
return nil
}
type LoginRequest struct {
WithSession
IPAddress string `json:"-"`
Email sharedTypes.Email `json:"email"`
Password UserPassword `json:"password"`
}
func (r *LoginRequest) Preprocess() {
r.Email = r.Email.Normalize()
}
func (r *LoginRequest) Validate() error {
if err := r.Password.Validate(); err != nil {
return err
}
if err := r.Email.Validate(); err != nil {
return err
}
return nil
}
type LoginResponse = asyncForm.Response
type LoginPageRequest struct {
WithSession
Referrer string `form:"-"`
}
type LoginPageResponse struct {
Data *templates.UserLoginData
Redirect string
}
type GetLoggedInUserJWTRequest struct {
WithSession
}
type GetLoggedInUserJWTResponse string
type ClearSessionsRequest struct {
WithSession
IPAddress string `json:"-"`
}
type SessionsPageRequest struct {
WithSession
}
type SessionsPageResponse struct {
Data *templates.UserSessionsData
}
type ChangeEmailAddressRequest struct {
WithSession
IPAddress string `json:"-"`
Email sharedTypes.Email `json:"email"`
}
func (r *ChangeEmailAddressRequest) Preprocess() {
r.Email = r.Email.Normalize()
}
func (r *ChangeEmailAddressRequest) Validate() error {
if err := r.Email.Validate(); err != nil {
return err
}
return nil
}
type SetUserName struct {
WithSession
FirstName string `json:"first_name"`
LastName string `json:"last_name"`
}
type SettingsPageRequest struct {
WithSession
}
type SettingsPageResponse struct {
Data *templates.UserSettingsData
}