Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea
6 changes: 6 additions & 0 deletions handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package auth

import (
"crypto/md5"
"encoding/json"
"fmt"
"html/template"
"mime"

"net/http"
"path"
"path/filepath"
Expand All @@ -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)
}

Expand Down
2 changes: 2 additions & 0 deletions providers/password/confirm.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"html/template"
"net/mail"
"os"
"path"
"reflect"
"time"
Expand Down Expand Up @@ -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",
Expand Down
4 changes: 3 additions & 1 deletion providers/password/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions providers/password/reset_password.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package password

import (
"net/mail"
"os"
"path"
"reflect"
"strings"
Expand Down Expand Up @@ -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,
Expand Down