Compare commits

..

1 Commits

Author SHA1 Message Date
Alf Sebastian Houge
d9a99d432c Make emails case insensitive 2022-03-07 00:17:35 +01:00
4 changed files with 31 additions and 10 deletions

View File

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

View File

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

View File

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

View File

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