public static UserModel GetFromEntity(ApplicationUser user) { return new UserModel { UserName = user.UserName, FirstName = user.FirstName, LastName = user.LastName, Email = user.Email, JoinDate = user.JoinDate, Active = user.Active, EmailConfirmed = user.EmailConfirmed, Id = user.Id, ImgName = user.ImgName }; }
public UserReturnModel Create(ApplicationUser appUser) { return new UserReturnModel { Url = _UrlHelper.Link("GetUserById", new { id = appUser.Id }), Id = appUser.Id, UserName = appUser.UserName, FullName = string.Format("{0} {1}", appUser.FirstName, appUser.LastName), Email = appUser.Email, EmailConfirmed = appUser.EmailConfirmed, Level = appUser.Level, JoinDate = appUser.JoinDate, Roles = _AppUserManager.GetRolesAsync(appUser.Id).Result, Claims = _AppUserManager.GetClaimsAsync(appUser.Id).Result }; }
public static IEnumerable<Claim> GetClaims(ApplicationUser user) { List<Claim> claims = new List<Claim>(); var daysInWork = (DateTime.Now.Date - user.JoinDate).TotalDays; if (daysInWork > 90) { claims.Add(CreateClaim("FTE", "1")); } else { claims.Add(CreateClaim("FTE", "0")); } return claims; }
public async Task<IdentityResult> RegisterUser(UserModel userModel) { if (string.IsNullOrEmpty(userModel.Id)) userModel.Id = Guid.NewGuid().ToString(); ApplicationUser user = new ApplicationUser { UserName = userModel.UserName, Email = userModel.Email, FirstName = userModel.FirstName, LastName = userModel.LastName, EmailConfirmed = userModel.EmailConfirmed, Active = userModel.Active, JoinDate = DateTime.Now, Id = userModel.Id }; var result = await _userManager.CreateAsync(user, userModel.Password); await _ctx.SaveChangesAsync(); return result; }
public async Task<IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName, Level = 3, JoinDate = DateTime.Now.Date, }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return GetErrorResult(addUserResult); } string code = await this.AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = code })); await this.AppUserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>"); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return Created(locationHeader, TheModelFactory.Create(user)); }