public async Task <bool> UpdateProfile(Guid id, ApplicationUserDtocs input) { ApplicationUser user = _userManager.Users.Where(i => i.Id == id && !i.isDeleted).FirstOrDefault(); if (user != null) { user.firstName = input.firstName; user.lastName = input.lastName; user.PhoneNumber = input.PhoneNumber; user.PasswordHash = input.PasswordHash; user.UserName = input.UserName; user.Email = input.Email; //user.EmailConfirmed = input.EmailConfirmed; user.isDeleted = input.isDeleted; IdentityResult result = await _userManager.UpdateAsync(user); if (result.Succeeded) { return(true); } else { return(false); }; } return(false); }
public IActionResult EditUser(Guid id, [FromBody] ApplicationUserDtocs userInfo) { if (!ModelState.IsValid) { return(BadRequest()); } var res = _profileManager.UpdateProfile(id, userInfo); if (res.Result) { return(Ok(true)); } return(NotFound()); }
public string GetAuthToken(ApplicationUserDtocs profile, string password) { var confgManager = new ConfigurationsManager(); var tokenDescriptor = new SecurityTokenDescriptor { Subject = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, profile.firstName + profile.lastName), new Claim(ClaimTypes.PrimarySid, profile.Id.ToString()), }), Expires = DateTime.UtcNow.AddDays(7), SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(Encoding.ASCII.GetBytes(confgManager.Token)), SecurityAlgorithms.HmacSha256Signature) }; //foreach (var role in roles) // tokenDescriptor.Subject.AddClaim(new Claim(ClaimTypes.Role, role)); var tokenHandler = new JwtSecurityTokenHandler(); return(tokenHandler.WriteToken(tokenHandler.CreateToken(tokenDescriptor))); }
public async Task <bool> InsertUser(ApplicationUserDtocs userModel) { userModel.Id = Guid.NewGuid(); userModel.CreatedDate = DateTime.Now.Date; try { var user = _mapper.Map <ApplicationUser>(userModel); var result = await _userManager.CreateAsync(user, userModel.PasswordHash); if (result.Succeeded) { return(true); } return(false); } catch { return(false); } }
public async Task <IActionResult> CreateNewUser([FromBody] ApplicationUserDtocs userModel) { if (!ModelState.IsValid) { return(BadRequest()); } var res = await _profileManager.InsertUser(userModel); registerResult registerResult = new registerResult(); registerResult.success = res; if (res) { registerResult.token = _profileManager.GetAuthToken(userModel, userModel.PasswordHash); registerResult.id = userModel.Id; registerResult.firstName = userModel.firstName; registerResult.lastName = userModel.lastName; } return(Ok(registerResult)); }