better error messages.
This commit is contained in:
parent
b5e12c0374
commit
87db3cf751
|
@ -1,6 +1,7 @@
|
||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/auth"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/auth"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/database"
|
||||||
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
"github.com/fastenhealth/fastenhealth-onprem/backend/pkg/models"
|
||||||
|
@ -43,20 +44,20 @@ func AuthSignin(c *gin.Context) {
|
||||||
|
|
||||||
foundUser, err := databaseRepo.GetUserByEmail(c, user.Username)
|
foundUser, err := databaseRepo.GetUserByEmail(c, user.Username)
|
||||||
if err != nil || foundUser == nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
err = foundUser.CheckPassword(user.Password)
|
err = foundUser.CheckPassword(user.Password)
|
||||||
if err != nil {
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
// return JWT
|
// return JWT
|
||||||
tokenString, err := auth.GenerateJWT(user.Username)
|
tokenString, err := auth.GenerateJWT(user.Username)
|
||||||
if err != nil {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
<div class="az-footer ht-40">
|
<div class="az-footer ht-40">
|
||||||
<div class="container ht-100p pd-t-0-f">
|
<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">
|
<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>
|
<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>
|
||||||
</div><!-- container -->
|
</div><!-- container -->
|
||||||
</div><!-- az-footer -->
|
</div><!-- az-footer -->
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
</div>
|
</div>
|
||||||
</div><!-- form-group -->
|
</div><!-- form-group -->
|
||||||
<button [disabled]="!userForm.form.valid" type="submit" class="btn btn-az-primary btn-block">Sign In</button>
|
<button [disabled]="!userForm.form.valid" type="submit" class="btn btn-az-primary btn-block">Sign In</button>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
</div><!-- az-signin-header -->
|
</div><!-- az-signin-header -->
|
||||||
<div class="az-signin-footer">
|
<div class="az-signin-footer">
|
||||||
|
|
Loading…
Reference in New Issue