Skip to content

Commit

Permalink
support signing in with email address
Browse files Browse the repository at this point in the history
  • Loading branch information
rystaf committed Jun 21, 2024
1 parent 9480ee2 commit 11dd0b2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
30 changes: 14 additions & 16 deletions routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,6 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
return
}
var token string
var username string
switch r.FormValue("submit") {
case "log in":
login := lemmy.Login{
Expand All @@ -916,7 +915,6 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}
if resp.JWT.IsValid() {
token = resp.JWT.String()
username = r.FormValue("username")
deleteCookie(w, state.Host, "ShowNSFW")
}
case "sign up":
Expand Down Expand Up @@ -947,7 +945,6 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
return
}
if resp.JWT.IsValid() {
username = r.FormValue("username")
token = resp.JWT.String()
} else {
var alert string
Expand All @@ -965,16 +962,16 @@ func SignUpOrLogin(w http.ResponseWriter, r *http.Request, ps httprouter.Params)
}
}
if token != "" {
state.GetUser(username)
if state.User == nil {
return
state.Client.Token = token
state.GetSite()
if myUser, ok := state.Site.MyUser.Value(); ok {
setCookie(w, state.Host, "jwt", token)
userid := strconv.FormatInt(myUser.LocalUserView.Person.ID, 10)
setCookie(w, state.Host, "user", myUser.LocalUserView.Person.Name+":"+userid)
setCookie(w, state.Host, "jwt", token)
r.URL.Path = "/" + state.Host
http.Redirect(w, r, r.URL.String(), http.StatusFound)
}
setCookie(w, state.Host, "jwt", token)
userid := strconv.FormatInt(state.User.PersonView.Person.ID, 10)
setCookie(w, state.Host, "user", state.User.PersonView.Person.Name+":"+userid)
setCookie(w, state.Host, "jwt", token)
r.URL.Path = "/" + state.Host
http.Redirect(w, r, r.URL.String(), http.StatusFound)
return
}
}
Expand Down Expand Up @@ -1120,11 +1117,12 @@ func UserOp(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
Render(w, "login.html", state)
return
} else if resp.JWT.IsValid() {
state.GetUser(r.FormValue("username"))
if state.User != nil {
state.Client.Token = resp.JWT.String()
state.GetSite()
if myuser, ok := state.Site.MyUser.Value(); ok {
setCookie(w, state.Host, "jwt", resp.JWT.String())
userid := strconv.FormatInt(state.User.PersonView.Person.ID, 10)
setCookie(w, state.Host, "user", state.User.PersonView.Person.Name+":"+userid)
userid := strconv.FormatInt(myuser.LocalUserView.Person.ID, 10)
setCookie(w, state.Host, "user", myuser.LocalUserView.Person.Name+":"+userid)
}
}
case "create_community":
Expand Down
2 changes: 1 addition & 1 deletion state.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (state *State) GetSite() {
if len(state.Site.Taglines) > 0 {
state.Tagline = state.Site.Taglines[rand.Intn(len(state.Site.Taglines))].Content
}
if !state.Site.MyUser.IsValid() {
if !state.Site.MyUser.IsValid() || state.Session == nil {
return
}
for _, c := range state.Site.MyUser.ValueOrZero().Follows {
Expand Down

0 comments on commit 11dd0b2

Please sign in to comment.