public async Task <InstitutionDTO> RegisterInstitution(Institution institution) { institution.Password = Cryptor.EncryptPassword(institution.Password); var result = await this.institutionRepository.CreateInstitution(institution); if (result != null) { return(this.mapper.Map <Institution, InstitutionDTO>(result)); } else { return(null); } }
public async Task <DataResult> ResetPassword(Institution institution) { var instFromServer = await this.institutionRepository.GetInstitutionById(institution.Id); if (Cryptor.DecryptPassword(instFromServer.Password, institution.Password)) { instFromServer.Password = Cryptor.EncryptPassword(institution.NewPassword); var result = await this.institutionRepository.UpdatePassword(instFromServer); if (result > 0) { var inst = this.mapper.Map <Institution, InstitutionDTO>(instFromServer); return(new DataResult(inst, Message.Successful)); } return(new DataResult(null, Message.ServerError)); } return(new DataResult(null, Message.IncorrectPassword)); }
public async Task <InstitutionDTO> Login(Institution institutionFromClient) { var institutionFromServer = await this.institutionRepository.GetInstitutionByLogin(institutionFromClient.Login); if (institutionFromServer != null) { var isValidPassword = Cryptor.DecryptPassword(institutionFromServer.Password, institutionFromClient.Password); if (isValidPassword) { return(this.mapper.Map <Institution, InstitutionDTO>(institutionFromServer)); } else { return(null); } } else { return(null); } }