public async Task <string> UpdateClientInfo([FromBody] Client clientDto) { var client = await _unitOfWork.Repository <User>().GetByIdAsync(clientDto.Id); client = Mapper.Map(clientDto, client); await _accountHelper.UpdateUserInfoAsync(client); return(AccountValidate.ValidationMessage(RequestState.Success, "Update Client success")); }
public async Task <string> UpdateMemberInfo([FromBody] Member memberDto) { var member = await _unitOfWork.Repository <User>().GetByIdAsync(memberDto.Id); member = Mapper.Map(memberDto, member); await _accountHelper.UpdateUserInfoAsync(member); return(AccountValidate.ValidationMessage(RequestState.Success, "Update Member success")); }
public async Task <string> DeleteAccount(string id) { if (id == null) { throw new ArgumentNullException(nameof(id)); } var clientToDelete = await _unitOfWork.Repository <User>().GetByIdAsync(id); await _unitOfWork.Repository <User>().DeleteAsync(clientToDelete); return(AccountValidate.ValidationMessage(RequestState.Success, "Delete account success")); }
public async Task <string> NewMember([FromBody] Member memberDto) { var account = await _accountHelper.CreateNewAccount(memberDto); await _userManager.AddToRoleAsync(account.User, memberDto.Role); var signUpInfo = new SignUpInfo { UserName = account.User.UserName, SignupUrl = account.CallbackUrl, RandomPassword = account.RandomPassword }; string bodyContent = await _emailTemplateService.RenderTemplateAsync("Account/AccountConfirm.cshtml", signUpInfo); await _emailSender.SendEmail(EmailType.MemberAccount, memberDto.Email, bodyContent); return(AccountValidate.ValidationMessage(RequestState.Success, "Create new member success")); }
public async Task <string> GetAuthToken([FromBody] LoginViewModel userDto) { var user = await _userManager.FindByNameAsync(userDto.Username); if (user == null) { return(AccountValidate.ValidationMessage(RequestState.Failed, "User account not exists")); } if (!await _userManager.IsEmailConfirmedAsync(user)) { return(AccountValidate.ValidationMessage(RequestState.Failed, "You must have a confirmed email to log in.")); } var result = await _signInManager.PasswordSignInAsync(userDto.Username, userDto.Password, false, true); if (result.IsLockedOut) { return(AccountValidate.ValidationMessage(RequestState.Failed, "User account locked out.")); } if (!result.Succeeded) { return(AccountValidate.ValidationMessage(RequestState.Failed, "Account credentails is not valid")); } var requesAt = DateTime.Now; var expiresIn = requesAt + TokenAuthOption.ExpiresSpan; //need to pass user id for generate token var token = TokenHelper.GenerateToken(user, expiresIn); return(JsonConvert.SerializeObject(new RequestResult { State = RequestState.Success, Data = new { requesAt, expiresIn = TokenAuthOption.ExpiresSpan.TotalSeconds, tokenType = TokenAuthOption.TokenType, accessToken = token } })); }