-
Notifications
You must be signed in to change notification settings - Fork 2.9k
feat: Update Login Page #7815
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: Update Login Page #7815
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -21,9 +21,9 @@ type IAuthService interface { | |
| CheckIsSafety(code string) (string, error) | ||
| GetResponsePage() (string, error) | ||
| VerifyCode(code string) (bool, error) | ||
| Login(c *gin.Context, info dto.Login, entrance string) (*dto.UserLoginInfo, error) | ||
| Login(c *gin.Context, info dto.Login, entrance string) (*dto.UserLoginInfo, string, error) | ||
| LogOut(c *gin.Context) error | ||
| MFALogin(c *gin.Context, info dto.MFALogin, entrance string) (*dto.UserLoginInfo, error) | ||
| MFALogin(c *gin.Context, info dto.MFALogin, entrance string) (*dto.UserLoginInfo, string, error) | ||
| GetSecurityEntrance() string | ||
| IsLogin(c *gin.Context) bool | ||
| } | ||
|
|
@@ -32,79 +32,86 @@ func NewIAuthService() IAuthService { | |
| return &AuthService{} | ||
| } | ||
|
|
||
| func (u *AuthService) Login(c *gin.Context, info dto.Login, entrance string) (*dto.UserLoginInfo, error) { | ||
| func (u *AuthService) Login(c *gin.Context, info dto.Login, entrance string) (*dto.UserLoginInfo, string, error) { | ||
| nameSetting, err := settingRepo.Get(repo.WithByKey("UserName")) | ||
| if err != nil { | ||
| return nil, buserr.New("ErrRecordNotFound") | ||
| return nil, "", buserr.New("ErrRecordNotFound") | ||
| } | ||
| passwordSetting, err := settingRepo.Get(repo.WithByKey("Password")) | ||
| if err != nil { | ||
| return nil, buserr.New("ErrRecordNotFound") | ||
| return nil, "", buserr.New("ErrRecordNotFound") | ||
| } | ||
| pass, err := encrypt.StringDecrypt(passwordSetting.Value) | ||
| if err != nil { | ||
| return nil, buserr.New("ErrAuth") | ||
| return nil, "ErrAuth", nil | ||
| } | ||
| if !hmac.Equal([]byte(info.Password), []byte(pass)) || nameSetting.Value != info.Name { | ||
| return nil, buserr.New("ErrAuth") | ||
| return nil, "ErrAuth", nil | ||
| } | ||
| entranceSetting, err := settingRepo.Get(repo.WithByKey("SecurityEntrance")) | ||
| if err != nil { | ||
| return nil, err | ||
| return nil, "", err | ||
| } | ||
| if len(entranceSetting.Value) != 0 && entranceSetting.Value != entrance { | ||
| return nil, buserr.New("ErrEntrance") | ||
| return nil, "ErrEntrance", nil | ||
| } | ||
| mfa, err := settingRepo.Get(repo.WithByKey("MFAStatus")) | ||
| if err != nil { | ||
| return nil, err | ||
| return nil, "", err | ||
| } | ||
| if err = settingRepo.Update("Language", info.Language); err != nil { | ||
| return nil, err | ||
| return nil, "", err | ||
| } | ||
| if mfa.Value == constant.StatusEnable { | ||
| return &dto.UserLoginInfo{Name: nameSetting.Value, MfaStatus: mfa.Value}, nil | ||
| return &dto.UserLoginInfo{Name: nameSetting.Value, MfaStatus: mfa.Value}, "", nil | ||
| } | ||
| return u.generateSession(c, info.Name, info.AuthMethod) | ||
| res, err := u.generateSession(c, info.Name, info.AuthMethod) | ||
| if err != nil { | ||
| return nil, "", err | ||
| } | ||
| return res, "", nil | ||
| } | ||
|
|
||
| func (u *AuthService) MFALogin(c *gin.Context, info dto.MFALogin, entrance string) (*dto.UserLoginInfo, error) { | ||
| func (u *AuthService) MFALogin(c *gin.Context, info dto.MFALogin, entrance string) (*dto.UserLoginInfo, string, error) { | ||
| nameSetting, err := settingRepo.Get(repo.WithByKey("UserName")) | ||
| if err != nil { | ||
| return nil, buserr.New("ErrRecordNotFound") | ||
| return nil, "", buserr.New("ErrRecordNotFound") | ||
| } | ||
| passwordSetting, err := settingRepo.Get(repo.WithByKey("Password")) | ||
| if err != nil { | ||
| return nil, buserr.New("ErrRecordNotFound") | ||
| return nil, "", buserr.New("ErrRecordNotFound") | ||
| } | ||
| pass, err := encrypt.StringDecrypt(passwordSetting.Value) | ||
| if err != nil { | ||
| return nil, err | ||
| return nil, "", err | ||
| } | ||
| if !hmac.Equal([]byte(info.Password), []byte(pass)) || nameSetting.Value != info.Name { | ||
| return nil, buserr.New("ErrAuth") | ||
| return nil, "ErrAuth", nil | ||
| } | ||
| entranceSetting, err := settingRepo.Get(repo.WithByKey("SecurityEntrance")) | ||
| if err != nil { | ||
| return nil, err | ||
| return nil, "", err | ||
| } | ||
| if len(entranceSetting.Value) != 0 && entranceSetting.Value != entrance { | ||
| return nil, buserr.New("ErrEntrance") | ||
| return nil, "", buserr.New("ErrEntrance") | ||
| } | ||
| mfaSecret, err := settingRepo.Get(repo.WithByKey("MFASecret")) | ||
| if err != nil { | ||
| return nil, err | ||
| return nil, "", err | ||
| } | ||
| mfaInterval, err := settingRepo.Get(repo.WithByKey("MFAInterval")) | ||
| if err != nil { | ||
| return nil, err | ||
| return nil, "", err | ||
| } | ||
| success := mfa.ValidCode(info.Code, mfaInterval.Value, mfaSecret.Value) | ||
| if !success { | ||
| return nil, buserr.New("ErrAuth") | ||
| return nil, "ErrAuth", nil | ||
| } | ||
|
|
||
| return u.generateSession(c, info.Name, info.AuthMethod) | ||
| res, err := u.generateSession(c, info.Name, info.AuthMethod) | ||
| if err != nil { | ||
| return nil, "", err | ||
| } | ||
| return res, "", nil | ||
| } | ||
|
|
||
| func (u *AuthService) generateSession(c *gin.Context, name, authMethod string) (*dto.UserLoginInfo, error) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like there is a logical inconsistency at line 43 of the |
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main differences from the previous version mentioned:
As for optimizations, it seems like most of the function implementations were updated for Go 1.18 compatibility.
Regarding potential issues or irregularities, there is no obvious indication of any errors found in the current code snippet except for minor syntax differences which are usually resolved when updating from a specific version to another one.
Suggestions to be implemented include checking if the 'AuthMethod' parameter has been provided and validating it properly before proceeding with other operations. Further checks on 'c', specifically its client IP address and user agent data might also aid in enhancing security measures.
Optimization could focus on performance improvements, possibly through avoiding unnecessary calls, making more efficient loops where possible using built-in functions available in GO (like
strconv.Atoi()), and handling larger slices and arrays optimally, ensuring that memory usage is optimized throughout the program's execution path.Note: The detailed analysis may require an environment to run these snippets under as this platform doesn't support interactive mode for running code.
Additionally, for efficiency gains consider implementing Go’s concurrency libraries such as goroutines or channel communication to improve system responsiveness.
For further details you can refer to the official documentation and community forums, as they often contain helpful insights about optimizing and improving Go programming practices in particular scenarios.