Change password

This commit is contained in:
Arnaud Delcasse 2022-10-30 20:09:51 +01:00
parent b9a32e41bf
commit 356bfc6a86
4 changed files with 29 additions and 6 deletions

3
go.sum
View File

@ -790,9 +790,6 @@ github.com/nicksnyder/go-i18n v1.10.0/go.mod h1:HrK7VCrbOvQoUAQ7Vpy7i87N7JZZZ7R2
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U=
github.com/oleiade/reflections v1.0.0/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60=
github.com/oleiade/reflections v1.0.1 h1:D1XO3LVEYroYskEsoSiGItp9RUxG6jWnCVvrqH0HHQM=
github.com/oleiade/reflections v1.0.1/go.mod h1:rdFxbxq4QXVZWj0F+e9jqjDkc7dbp97vkRixKo2JR60=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= github.com/onsi/ginkgo v1.8.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=

View File

@ -121,8 +121,12 @@ func (s MobilityAccountsServerImpl) GetAccountsBatch(ctx context.Context, req *G
} }
return &GetAccountsBatchResponse{Accounts: accounts}, nil return &GetAccountsBatchResponse{Accounts: accounts}, nil
} }
func (MobilityAccountsServerImpl) ChangePassword(ctc context.Context, req *ChangePasswordRequest) (*ChangePasswordResponse, error) { func (s MobilityAccountsServerImpl) ChangePassword(ctx context.Context, req *ChangePasswordRequest) (*ChangePasswordResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method not implemented") err := s.handler.ChangePassword(req.Id, req.Password)
if err != nil {
return nil, err
}
return &ChangePasswordResponse{}, nil
} }
func (MobilityAccountsServerImpl) mustEmbedUnimplementedMobilityAccountsServer() {} func (MobilityAccountsServerImpl) mustEmbedUnimplementedMobilityAccountsServer() {}

View File

@ -137,3 +137,23 @@ func (h MobilityAccountsHandler) GetAccountsBatch(accountIds []string) (accounts
accounts, err = h.storage.DB.GetAccountsByIds(accountIds) accounts, err = h.storage.DB.GetAccountsByIds(accountIds)
return return
} }
func (h MobilityAccountsHandler) ChangePassword(accountid string, newpassword string) error {
account, err := h.storage.DB.GetAccount(accountid)
if err != nil {
return err
}
hashedPassword, err := bcrypt.GenerateFromPassword([]byte(newpassword), bcrypt.DefaultCost)
if err != nil {
return err
}
account.Authentication.Local.Password = string(hashedPassword)
if err = h.storage.DB.UpdateAccount(*account); err != nil {
fmt.Println(err)
return err
}
return nil
}

View File

@ -57,10 +57,12 @@
</div> </div>
</div> </div>
<p class="p-4 text-center text-sm text-co-blue"><a href="http://localhost:9000/auth/lost-password">Mot de passe oublié</a></p>
<div> <div>
<button type="submit" class="mt-2 flex w-full justify-center rounded-2xl border border-transparent bg-co-blue py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-co-blue focus:outline-none focus:ring-2 focus:ring-co-blue focus:ring-offset-2">Sign in</button> <button type="submit" class="mt-2 flex w-full justify-center rounded-2xl border border-transparent bg-co-blue py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-co-blue focus:outline-none focus:ring-2 focus:ring-co-blue focus:ring-offset-2">Se connecter</button>
</div> </div>