diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..723ef36 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.idea \ No newline at end of file diff --git a/handlers.go b/handlers.go index d102fe4..52072c0 100644 --- a/handlers.go +++ b/handlers.go @@ -2,9 +2,11 @@ package auth import ( "crypto/md5" + "encoding/json" "fmt" "html/template" "mime" + "net/http" "path" "path/filepath" @@ -25,6 +27,10 @@ func respondAfterLogged(claims *claims.Claims, context *Context) { context.Auth.Redirector.Redirect(context.Writer, context.Request, "login") }).With([]string{"json"}, func() { // TODO write json token + var response = map[string]interface{}{} + response["access_token"] = context.Auth.SessionStorer.SignedToken(claims) + response["success"] = true + json.NewEncoder(context.Writer).Encode(&response) }).Respond(context.Request) } diff --git a/providers/password/confirm.go b/providers/password/confirm.go index fc04e41..6db16e9 100644 --- a/providers/password/confirm.go +++ b/providers/password/confirm.go @@ -4,6 +4,7 @@ import ( "errors" "html/template" "net/mail" + "os" "path" "reflect" "time" @@ -40,6 +41,7 @@ var DefaultConfirmationMailer = func(email string, context *auth.Context, claims return context.Auth.Mailer.Send( mailer.Email{ TO: []mail.Address{{Address: email}}, + From: &mail.Address{Address: os.Getenv("SMTP_FROM")}, Subject: ConfirmationMailSubject, }, mailer.Template{ Name: "auth/confirmation", diff --git a/providers/password/handlers.go b/providers/password/handlers.go index b8e7a94..a63e005 100644 --- a/providers/password/handlers.go +++ b/providers/password/handlers.go @@ -75,6 +75,8 @@ var DefaultRegisterHandler = func(context *auth.Context) (*claims.Claims, error) schema.UID = authInfo.UID schema.Email = authInfo.UID schema.RawInfo = req + schema.FirstName = req.Form.Get("first_name") + schema.LastName = req.Form.Get("last_name") currentUser, authInfo.UserID, err = context.Auth.UserStorer.Save(&schema, context) if err != nil { @@ -83,7 +85,7 @@ var DefaultRegisterHandler = func(context *auth.Context) (*claims.Claims, error) // create auth identity authIdentity := reflect.New(utils.ModelType(context.Auth.Config.AuthIdentityModel)).Interface() - if err = tx.Where("provider = ? AND uid = ?", authInfo.Provider, authInfo.UID).FirstOrCreate(authIdentity).Error; err == nil { + if err = tx.Where("provider = ? AND uid = ?", authInfo.Provider, authInfo.UID).Attrs("EncryptedPassword", authInfo.EncryptedPassword).Attrs("UserID", authInfo.UserID).Attrs("Provider", authInfo.Provider).Attrs("UID", authInfo.UID).FirstOrCreate(authIdentity).Error; err == nil { if provider.Config.Confirmable { context.SessionStorer.Flash(context.Writer, req, session.Message{Message: ConfirmFlashMessage, Type: "success"}) err = provider.Config.ConfirmMailer(schema.Email, context, authInfo.ToClaims(), currentUser) diff --git a/providers/password/reset_password.go b/providers/password/reset_password.go index 3179cca..08b887c 100644 --- a/providers/password/reset_password.go +++ b/providers/password/reset_password.go @@ -2,6 +2,7 @@ package password import ( "net/mail" + "os" "path" "reflect" "strings" @@ -36,6 +37,7 @@ var DefaultResetPasswordMailer = func(email string, context *auth.Context, claim mailer.Email{ TO: []mail.Address{{Address: email}}, Subject: ResetPasswordMailSubject, + From: &mail.Address{Address: os.Getenv("SMTP_FROM")}, }, mailer.Template{ Name: "auth/reset_password", Data: context,