Compare commits

..

1 Commits

Author SHA1 Message Date
Alf Sebastian Houge
43d1ca0c66 Tag login email field as email type 2022-04-17 18:53:15 +02:00
4 changed files with 10 additions and 31 deletions

View File

@@ -5,7 +5,6 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"os" "os"
"strings"
"github.com/akhilrex/hammond/common" "github.com/akhilrex/hammond/common"
"github.com/akhilrex/hammond/db" "github.com/akhilrex/hammond/db"
@@ -92,7 +91,7 @@ func userLogin(c *gin.Context) {
c.JSON(http.StatusUnprocessableEntity, common.NewValidatorError(err)) c.JSON(http.StatusUnprocessableEntity, common.NewValidatorError(err))
return return
} }
user, err := db.FindOneUser(&db.User{Email: strings.ToLower(loginRequest.Email)}) user, err := db.FindOneUser(&db.User{Email: loginRequest.Email})
if err != nil { if err != nil {
c.JSON(http.StatusForbidden, common.NewError("login", errors.New("Not Registered email or invalid password"))) c.JSON(http.StatusForbidden, common.NewError("login", errors.New("Not Registered email or invalid password")))

View File

@@ -18,10 +18,6 @@ var migrations = []localMigration{
Name: "2021_06_24_04_42_SetUserDisabledFalse", Name: "2021_06_24_04_42_SetUserDisabledFalse",
Query: "update users set is_disabled=0", Query: "update users set is_disabled=0",
}, },
{
Name: "2021_02_07_00_09_LowerCaseEmails",
Query: "update users set email=lower(email)",
},
} }
func RunMigrations() { func RunMigrations() {

View File

@@ -1,8 +1,6 @@
package service package service
import ( import (
"strings"
"github.com/akhilrex/hammond/db" "github.com/akhilrex/hammond/db"
"github.com/akhilrex/hammond/models" "github.com/akhilrex/hammond/models"
) )
@@ -10,7 +8,7 @@ import (
func CreateUser(userModel *models.RegisterRequest, role db.Role) error { func CreateUser(userModel *models.RegisterRequest, role db.Role) error {
setting := db.GetOrCreateSetting() setting := db.GetOrCreateSetting()
toCreate := db.User{ toCreate := db.User{
Email: strings.ToLower(userModel.Email), Email: userModel.Email,
Name: userModel.Name, Name: userModel.Name,
Role: role, Role: role,
Currency: setting.Currency, Currency: setting.Currency,

View File

@@ -16,7 +16,7 @@ export default {
password: '', password: '',
authError: null, authError: null,
tryingToLogIn: false, tryingToLogIn: false,
errorMessage:'' errorMessage: '',
} }
}, },
computed: { computed: {
@@ -38,7 +38,7 @@ export default {
// and password they provided. // and password they provided.
tryToLogIn() { tryToLogIn() {
this.tryingToLogIn = true this.tryingToLogIn = true
this.errorMessage=''; this.errorMessage = ''
// Reset the authError if it existed. // Reset the authError if it existed.
this.authError = null this.authError = null
return this.logIn({ return this.logIn({
@@ -53,9 +53,9 @@ export default {
// Redirect to the originally requested page, or to the home page // Redirect to the originally requested page, or to the home page
}) })
.catch((error) => { .catch((error) => {
if(error.response.data?.errors?.login){ if (error.response.data?.errors?.login) {
this.errorMessage=error.response.data.errors.login this.errorMessage = error.response.data.errors.login
} }
this.tryingToLogIn = false this.tryingToLogIn = false
this.authError = error this.authError = error
}) })
@@ -67,21 +67,9 @@ export default {
<template> <template>
<Layout> <Layout>
<form @submit.prevent="tryToLogIn"> <form @submit.prevent="tryToLogIn">
<b-field label="Email"> <b-field label="Email"> <b-input v-model="username" tag="b-input" name="username" type="email" :placeholder="placeholders.username"/></b-field>
<b-input
v-model="username"
tag="b-input"
name="username"
:placeholder="placeholders.username"
/></b-field>
<b-field label="Password"> <b-field label="Password">
<b-input <b-input v-model="password" tag="b-input" name="password" type="password" :placeholder="placeholders.password" />
v-model="password"
tag="b-input"
name="password"
type="password"
:placeholder="placeholders.password"
/>
</b-field> </b-field>
<b-button tag="input" native-type="submit" :disabled="tryingToLogIn" type="is-primary"> <b-button tag="input" native-type="submit" :disabled="tryingToLogIn" type="is-primary">
<BaseIcon v-if="tryingToLogIn" name="sync" spin /> <BaseIcon v-if="tryingToLogIn" name="sync" spin />
@@ -89,9 +77,7 @@ export default {
Log in Log in
</span> </span>
</b-button> </b-button>
<p v-if="authError"> <p v-if="authError"> There was an error logging in to your account. {{ errorMessage }} </p>
There was an error logging in to your account. {{errorMessage}}
</p>
</form> </form>
</Layout> </Layout>
</template> </template>