Exemple #1
0
        public JsonResult <IDtoOutObjects> ChangePassword(DtoInChangePassword dtoInChangePassword)
        {
            if (ModelState.IsValid)
            {
                return(Json(_credentialModel.ChangePassword(dtoInChangePassword)));
            }

            DtoOutError error = new DtoOutError();

            error.Exception = new ObjectIsNotValidException("CredentialDto");
            error.Message   = "CredentialDto is not valid";
            return(Json((IDtoOutObjects)error));
        }
Exemple #2
0
        public IDtoOutObjects ChangePassword(DtoInChangePassword dtoInChangePassword)
        {
            DtoOutError error = new DtoOutError();

            if (TokenTools.Authentication(dtoInChangePassword.Token, dtoInChangePassword.DeviceName))
            {
                User       user       = TokenTools.getUserFromToken(dtoInChangePassword.Token);
                Credential credential = _credentialsRepository.FindBy(x => x.IdUser == user.Id && x.IsDeleted == false && x.ObjectUser.IsDeleted == false).FirstOrDefault(); // toto zanmená že každý user může mít jen jedny credentials
                credential.Password = dtoInChangePassword.Password;
                _credentialsRepository.Edit(credential);
                _credentialsRepository.Save();
                DtoOutComplete dtoOutComplete = new DtoOutComplete();
                dtoOutComplete.Completed = true;
                return(dtoOutComplete);
            }
            else
            {
                NotAuthenticatedException ex = new NotAuthenticatedException();
                error.Exception = ex;
                return(error);
            }
        }