better error messages.

This commit is contained in:
Jason Kulatunga 2022-09-12 17:34:03 -04:00
parent b5e12c0374
commit 87db3cf751
3 changed files with 7 additions and 5 deletions

View File

@ -1,6 +1,7 @@
package handler
import (
"fmt"
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/auth"
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database"
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
@ -43,20 +44,20 @@ func AuthSignin(c *gin.Context) {
foundUser, err := databaseRepo.GetUserByEmail(c, user.Username)
if err != nil || foundUser == nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": fmt.Sprintf("could not find user: %s", user.Username)})
return
}
err = foundUser.CheckPassword(user.Password)
if err != nil {
c.JSON(http.StatusUnauthorized, gin.H{"success": false})
c.JSON(http.StatusUnauthorized, gin.H{"success": false, "error": fmt.Sprintf("username or password does not match: %s", user.Username)})
return
}
// return JWT
tokenString, err := auth.GenerateJWT(user.Username)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"success": false})
c.JSON(http.StatusInternalServerError, gin.H{"success": false, "error": "an error occurred generating JWT token"})
return
}

View File

@ -1,7 +1,7 @@
<div class="az-footer ht-40">
<div class="container ht-100p pd-t-0-f">
<div class="d-sm-flex justify-content-center justify-content-sm-between py-2 w-100">
<span class="text-muted text-center text-sm-left d-block d-sm-inline-block">Copyright © bootstrapdash.com 2020</span>
<span class="text-muted text-center text-sm-left d-block d-sm-inline-block">Copyright © Fasten Health 2020</span>
<span class="float-none float-sm-right d-block mt-1 mt-sm-0 text-center">Free <a href="https://www.bootstrapdash.com/angular-admin-templates/" target="_blank"> angular admin template </a> from <a href="https://www.bootstrapdash.com/" target="_blank">bootstrapdash.com </a></span>
</div>
</div><!-- container -->

View File

@ -36,6 +36,7 @@
</div>
</div><!-- form-group -->
<button [disabled]="!userForm.form.valid" type="submit" class="btn btn-az-primary btn-block">Sign In</button>
</form>
</div><!-- az-signin-header -->
<div class="az-signin-footer">