-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler_reset_password_check_get.go
executable file
·63 lines (52 loc) · 1.61 KB
/
handler_reset_password_check_get.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
package handlers
import (
"net/http"
"strings"
"github.com/Sirupsen/logrus"
"github.com/IlijevskiSymphony/symphonyGopher/server/configuration"
"github.com/IlijevskiSymphony/symphonyGopher/server/partners"
"github.com/IlijevskiSymphony/symphonyGopher/server/passwordreset"
"github.com/gorilla/sessions"
"github.com/pborman/uuid"
mgo "gopkg.in/mgo.v2"
)
type HandlerResetPasswordCheckGet struct {
Configuration configuration.Configuration
SessionFn func() *mgo.Session
Store *sessions.CookieStore
}
func (h HandlerResetPasswordCheckGet) ServeHTTP(w http.ResponseWriter, req *http.Request) {
id := strings.TrimPrefix(req.URL.Path, "/resetPasswordCheck/")
if uuid.Parse(id) == nil {
logrus.Infof("Registration verification link is not valid.")
w.WriteHeader(http.StatusUnauthorized)
return
}
partnersRepo := partners.NewRepository(h.SessionFn())
defer partnersRepo.Close()
passwordReset := passwordreset.NewRepository(h.SessionFn())
defer passwordReset.Close()
rp, err := passwordReset.FindByReference(id)
if err != nil {
logrus.Infof("Cannot find password reset for partner. Error: %s", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if rp == nil {
logrus.Info("Password reset with given id doesn't exists")
w.WriteHeader(http.StatusUnauthorized)
return
}
p, err := partnersRepo.FindByID(rp.PartnerID)
if err != nil {
logrus.Infof("Cannot find partner. Error: %s", err)
w.WriteHeader(http.StatusInternalServerError)
return
}
if p == nil {
logrus.Info("Partner with given email doesn't exists")
w.WriteHeader(http.StatusUnauthorized)
return
}
return
}