@ -23,19 +23,23 @@ import (
// UserSignIn validates user name and password.
// UserSignIn validates user name and password.
func UserSignIn ( username , password string ) ( * user_model . User , * auth . Source , error ) {
func UserSignIn ( username , password string ) ( * user_model . User , * auth . Source , error ) {
var user * user_model . User
var user * user_model . User
isEmail := false
if strings . Contains ( username , "@" ) {
if strings . Contains ( username , "@" ) {
isEmail = true
emailAddress := user_model . EmailAddress { LowerEmail : strings . ToLower ( strings . TrimSpace ( username ) ) }
emailAddress := user_model . EmailAddress { LowerEmail : strings . ToLower ( strings . TrimSpace ( username ) ) }
// check same email
// check same email
has , err := db . GetEngine ( db . DefaultContext ) . Where ( "is_activated=?" , true ) . Get ( & emailAddress )
has , err := db . GetEngine ( db . DefaultContext ) . Get ( & emailAddress )
if err != nil {
if err != nil {
return nil , nil , err
return nil , nil , err
}
}
if ! has {
if has {
if ! emailAddress . IsActivated {
return nil , nil , user_model . ErrEmailAddressNotExist {
return nil , nil , user_model . ErrEmailAddressNotExist {
Email : username ,
Email : username ,
}
}
}
}
user = & user_model . User { ID : emailAddress . UID }
user = & user_model . User { ID : emailAddress . UID }
}
} else {
} else {
trimmedUsername := strings . TrimSpace ( username )
trimmedUsername := strings . TrimSpace ( username )
if len ( trimmedUsername ) == 0 {
if len ( trimmedUsername ) == 0 {
@ -45,6 +49,7 @@ func UserSignIn(username, password string) (*user_model.User, *auth.Source, erro
user = & user_model . User { LowerName : strings . ToLower ( trimmedUsername ) }
user = & user_model . User { LowerName : strings . ToLower ( trimmedUsername ) }
}
}
if user != nil {
hasUser , err := user_model . GetUser ( user )
hasUser , err := user_model . GetUser ( user )
if err != nil {
if err != nil {
return nil , nil , err
return nil , nil , err
@ -78,6 +83,7 @@ func UserSignIn(username, password string) (*user_model.User, *auth.Source, erro
return user , source , nil
return user , source , nil
}
}
}
sources , err := auth . AllActiveSources ( )
sources , err := auth . AllActiveSources ( )
if err != nil {
if err != nil {
@ -111,5 +117,9 @@ func UserSignIn(username, password string) (*user_model.User, *auth.Source, erro
}
}
}
}
if isEmail {
return nil , nil , user_model . ErrEmailAddressNotExist { Email : username }
}
return nil , nil , user_model . ErrUserNotExist { Name : username }
return nil , nil , user_model . ErrUserNotExist { Name : username }
}
}