public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new User() { UserName = createUserModel.Username, Email = createUserModel.Email, Name = createUserModel.Name, Surname = createUserModel.Surname, EmailConfirmed = true, }; 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 })); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
private bool CreateCustomUser(CreateUserBindingModel model) { string hash, stamp; CreateHashNStamp(model.UserID, string.IsNullOrWhiteSpace(model.Password) ? DefaultPassword : model.Password, out hash, out stamp); AspNetUser user = new AspNetUser() { Id = Guid.NewGuid().ToString(), UserName = model.UserID, Email = model.UserID, PasswordHash = hash, SecurityStamp = stamp }; Tenant tn = TenantHandler.GetTenantByName(model.Tenant); if (tn != null) { user.TenantId = tn.Id; } dbCtx.AspNetUsers.Add(user); int savedNum = dbCtx.SaveChanges(); return(savedNum > 0 && user != null); }
public async Task <IHttpActionResult> CreateUser([FromBody] CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, empleado = new Empleado() { DNI = createUserModel.DNI, Legajo = createUserModel.Legajo, NombreYApellido = createUserModel.FirstName + " " + createUserModel.LastName }, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName, }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
public IHttpActionResult RegisterUser([FromBody] CreateUserBindingModel userModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } try { if ((UnitOfWork.UserRepository.GetByName(userModel.UserName) != null) || (UnitOfWork.UserRepository.GetByEmail(userModel.Email) != null)) { return(Conflict()); } var user = Mapper.Map <CreateUserBindingModel, User>(userModel); user.Id = 0; // reset Id user.UserRole = UnitOfWork.RoleRepository.Get("User"); UnitOfWork.UserRepository.Add(user); UnitOfWork.Save(); Uri locationHeader = new Uri(Url.Link("GetUserById", new { userId = user.Id })); return(Created(locationHeader, Mapper.Map <User, UserReturnModelWithToken>(user))); } catch (Exception) { return(InternalServerError()); } }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // TODO: Get Employee Data from GP using the EmployeeId and inserting it into Employee Table var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, await ModelFactory.Create(user))); }
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); } //generate token and send confirmation mail 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)); }
public string CreateUser(CreateUserBindingModel model) { string ret = ""; try { Tenant tn = null; if (!string.IsNullOrEmpty(model.Tenant)) { tn = TenantHandler.GetTenantByName(model.Tenant); } if (dbCtx.AspNetUsers.Any(u => (u.UserName.ToLower().Equals(model.UserID.ToLower())) && (tn == null ? u.TenantId == null : u.TenantId == tn.Id))) { throw new AppException("The user ID: \"" + model.UserID + "\" conflicts with the name in our DB" + (tn == null ? "":(" for tenant " + tn.Name))); } bool isSaved = CreateCustomUser(model); if (isSaved) { isSaved = CreateIzendaUser(model); } if (!isSaved) { ret = "Create user failed."; } } catch (AppException ex) { ret = ex.Message; } return(ret); }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new AuthenticationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, Level = 3, }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
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 }; var addUserResult = await AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } var locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, ModelFactory.Create(user))); }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new UserMaster { UserName = createUserModel.Username, Email = createUserModel.Username, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName, JoinDate = DateTime.Now.Date, Level = (byte)(createUserModel.RoleName == "Provider" ? RoleType.Provider : RoleType.User) }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } return(Ok(createUserModel)); }
}//add jhon public static CreateUserBindingModel AddSam() { var model = new CreateUserBindingModel { FirstName = "Samuel", LastName = "Barreiro", BirthDate = "06/09/1986", email = "*****@*****.**", userName = "******", PhoneNumber = "07376095123", AgeRange = "17-21", dateAdded = DateTime.Today.ToShortDateString(), address = new CreateAddressBindingModel { lineOne = "78 Overstone Road", lineTwo = "", city = "London", lineThree = "", postCode = "W6 0AE", country = "UK", isbilling = true, isshipping = true, } }; return(model); }//add Sam
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (createUserModel == null) { return(BadRequest("Error. Model is empty")); } var user = new ApplicationUserDto() { UserName = createUserModel.Username, Email = createUserModel.Email, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName }; var addUserResult = await userService.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } await AssignRolesToUser(user.Id, new[] { "User" }); var locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, user)); }
public async Task <IHttpActionResult> Post(CreateUserBindingModel createUserModel) { Validate(createUserModel); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new User() { UserName = createUserModel.Username, Email = createUserModel.Email, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } var newModel = TheModelFactory.Create(user); return(CreatedAtRoute("GetUserById", new { userId = newModel.Id }, newModel)); }
public static CreateUserBindingModel AddMayra() { var model = new CreateUserBindingModel { FirstName = "Mayra", LastName = "Palomino", BirthDate = "20/05/1991", email = "*****@*****.**", userName = "******", PhoneNumber = "07376095124", AgeRange = "25-35", dateAdded = DateTime.Today.ToShortDateString(), address = new CreateAddressBindingModel { lineOne = "78 Overstone Road", lineTwo = "", city = "London", lineThree = "", postCode = "W6 0AA", country = "UK", isbilling = true, isshipping = true, } }; return(model); }//mayra
}//add Sam public static CreateUserBindingModel AddLuis() { var model = new CreateUserBindingModel { FirstName = "Luis A", LastName = "Torres", BirthDate = "06/09/1976", email = "*****@*****.**", userName = "******", PhoneNumber = "07376095123", AgeRange = "36-45", dateAdded = DateTime.Today.ToShortDateString(), address = new CreateAddressBindingModel { lineOne = "79 Overstone Road", lineTwo = "", city = "London", lineThree = "", postCode = "W6 0EE", country = "UK", isbilling = true, isshipping = true, } }; return(model); }//add lacho
public async Task <IHttpActionResult> Create(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Username, AccountCreated = DateTimeOffset.Now, }; IdentityResult addUserResult = await AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetIdentityErrorResult(addUserResult)); } //Uri locationHeader = new Uri(Url.Link("GetUser", new { Id = user.Id })); //return Created(locationHeader, _mapper.Map<UserViewModel>(user)); return(Ok()); }
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); } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return Created(locationHeader, TheModelFactory.Create(user)); }
/// <summary> /// Add new user. Validate model and if username/email has not been taken, creates a new user record, otherwys, returns an invalid message /// </summary> /// <param name="user"></param> /// <param name="collection"></param> /// <returns>Ok if successful, </returns> public static string AddNewUser(CreateUserBindingModel user, string collection) { string response = "Ok"; bool emailExists = FindUserEmail.EmailExists(user.email, collection); bool userNameExists = FindUserName.UsernameExists(user.userName, collection); if (emailExists == false && userNameExists == false) { //First build the user via the factory BsonDocument userDoc = UserFactory.CreateMongoUser(user); var _repo = new UserRepository(); return(_repo.AddUSer(userDoc, collection)); } else { if (userNameExists == true) { response = "Username already taken"; } else if (emailExists == true) { response = "Email address already taken"; } } return(response); }
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))); }
public async Task <IActionResult> Create(CreateUserBindingModel binding) { if (!ModelState.IsValid) { AddError("Error", ModelState, state => state.Children != null && state.Children.Any() /*checks for IValidatableObject (because those have children)*/); return(View(binding.ConvertTo <CreateUserViewModel>())); } var item = binding.ConvertTo <User>(); var user = new User { UserName = binding.EmailAddress, Email = binding.EmailAddress, FirstName = binding.FirstName, LastName = binding.LastName, PhoneNumber = binding.Phone }; var result = await UserManager.CreateAsync(user, binding.Password); if (result.Errors.Any()) { AddError("Error", string.Join("\r\n", result.Errors.Select(e => e.Description))); return(View(binding.ConvertTo <CreateUserViewModel>())); } DataContext.SaveChanges(); AddSuccess("Success", $"Created user {binding.EmailAddress} successfully"); return(RedirectToAction("Index")); }
public IHttpActionResult CreateUser(CreateUserBindingModel model) { if (!ModelState.IsValid || model == null) { return(BadRequest(ModelState)); } var user = new User() { UserName = model.Username, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, PasswordHash = Criptografia.Criptografar(model.Password) }; // IdentityResult addUserResult = this.UserRepository.Create(user, createUserModel.Password); UserRepository.AddUser(user); // if (!addUserResult.Succeeded) // { // return GetErrorResult(addUserResult); // } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
public SigninViewModel() { _navigationService = new NavigationService(); _authenticatorService = new AuthenticatorService(); Model = new CreateUserBindingModel { Username = "******", Password = "******", ConfirmPassword = "******", Email = "[email protected]", FirstName = "Test1", LastName = "User1", //RoleName = "" }; if (!string.IsNullOrEmpty(Settings.Username)) { Model.Username = Settings.Username; } if (!string.IsNullOrEmpty(Settings.Email)) { Model.Email = Settings.Email; } if (!string.IsNullOrEmpty(Settings.Password)) { Model.Password = Settings.Password; } }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } RespuestaDTO <UserDTO> user = await new UserBLL(Request).createUser(new CreateUserDTO { UserName = createUserModel.Username, Email = createUserModel.Email, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName, Level = 3, JoinDate = DateTime.Now.Date, Password = createUserModel.Password }); if (user.Error.Count > 0) { return(GetErrorResult(user)); } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Data.Id })); return(Created(locationHeader, user)); }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new User() { UserName = createUserModel.Username, Email = createUserModel.Email, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName, Level = 3, JoinDate = DateTime.Now.Date, }; IdentityResult addUserResult = await this.UserManager.CreateAsync(user, createUserModel.Password); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Ok(User)); }
public static BsonDocument CreateMongoUser(CreateUserBindingModel user) { var document = new BsonDocument { { "_id", ObjectId.GenerateNewId() }, { "userName", user.userName }, { "FirstName", user.FirstName }, { "LastName", user.LastName }, { "PhoneNumber", user.PhoneNumber }, { "BirthDate", user.BirthDate }, { "AgeRange", user.AgeRange }, { "email", user.email }, { "dateAdded", DateTime.Today.ToLongDateString() }, { "address", new BsonDocument { { "_id", ObjectId.GenerateNewId() }, { "lineOne", user.address.lineOne }, { "lineTwo", user.address.lineTwo }, { "lineThree", user.address.lineThree }, { "city", user.address.city }, { "postCode", user.address.postCode } } } }; return(document); }
/// <summary> /// Signup the user to the API. /// </summary> /// <param name="model"></param> /// <returns></returns> public async Task <AuthResponse> SignupAsync(CreateUserBindingModel model) { var json = JsonConvert.SerializeObject(model); HttpContent httpContent = new StringContent(json); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); HttpResponseMessage response = null; AuthResponse result = null; try { using (var client = new HttpClient()) { response = await client.PostAsync( "http://localhost:51502/api/accounts/create", httpContent); } } catch (Exception e) { result = new AuthResponse { IsSuccess = false, Result = "Something went wrong..." + e.Message, }; } var content = response?.Content?.ReadAsStringAsync(); if (content != null) { var r = await content; if (!response.IsSuccessStatusCode) { // something went wrong... result = new AuthResponse { IsSuccess = false, Result = "Something went wrong..." + r, }; } else { result = new AuthResponse { IsSuccess = true, Result = "Signup done successfully. " + "Please confirm your registration " + "by clicking the link in the provided email. " + "Then you can login.", }; } } return(result); }
public async Task <IHttpActionResult> AddUser(CreateUserBindingModel model) { //return Ok("hello world."); if (!ModelState.IsValid) { return(BadRequest(ModelState)); } //FogToken t = await FogAddUser(model, Helper.FogRegisterURL); //if (null == t) // return BadRequest(ModelState); FogToken t = await FogCheck(model); if (null == t) { return(BadRequest(ModelState)); } var user = new AppUser() { UserName = model.Username, Email = "[email protected]", //FirstName = createUserModel.FirstName, //LastName = createUserModel.LastName, //Level = 3, //JoinDate = DateTime.Now.Date, UserToken = t.user_token, UserKey = t.user_id //////id is right? }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, model.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 })); UserToken u = CreateToken(model.Username, model.Password); u.fog_user_id = t.user_id; u.fog_user_token = t.user_token; return(Ok(u)); }
public async Task <IHttpActionResult> ResetPassword(CreateUserBindingModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } FogToken t = await FogAddUser(model, Helper.FOGRESETPASSWORDURL); if (null == t) { return(BadRequest(ModelState)); } var user = await AppUserManager.FindByNameAsync(model.Username); if (null == user) { return(BadRequest()); } string resetToken = await AppUserManager.GeneratePasswordResetTokenAsync(user.Id); IdentityResult result = await AppUserManager.ResetPasswordAsync(user.Id, resetToken, model.Password); if (null == result) { return(BadRequest()); } t = await FogCheck(model); if (null == t) { return(BadRequest(ModelState)); } if (!user.UserToken.Equals(t.user_token) || !user.UserKey.Equals(t.user_id)) { user.UserToken = t.user_token; user.UserKey = t.user_id; IdentityResult x = await AppUserManager.UpdateAsync(user); if (null == x) { return(BadRequest()); } } UserToken u = CreateToken(model.Username, model.Password); u.fog_user_id = t.user_id; u.fog_user_token = t.user_token; return(Ok(u)); }
public ServiceResult <UserViewModel> Create(CreateUserBindingModel request) { var User = _mapper.Map <Domain.User>(request); _userRepository.Add(User); _unitOfWork.Commit(); return(new ServiceResult <UserViewModel>(_mapper.Map <UserViewModel>(User))); }
public async Task <IHttpActionResult> CreateAdmin(CreateUserBindingModel createUserModel) { //throw new ApiBusinessException(0002, "Nombre de usuario duplicado", System.Net.HttpStatusCode.BadRequest, "Http"); using (var dataContext = HttpContext.Current.GetOwinContext().Get <ApplicationDbContext>()) { using (var trans = dataContext.Database.BeginTransaction(IsolationLevel.ReadCommitted)) { try { var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, Name = createUserModel.Name, //LastName = createUserModel.LastName, //Level = 3, //JoinDate = DateTime.Now.Date, EmailConfirmed = true }; var role = new CreateRoleBindingModel() { Name = createUserModel.RoleName }; IdentityResult addUserResult = await this.AppUserManager .CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { trans.Rollback(); return(GetErrorResult(addUserResult)); } IdentityResult addUserToRoleResult = await this.AppUserManager. AddToRoleAsync(user.Id, role.Name); if (!addUserToRoleResult.Succeeded) { trans.Rollback(); return(GetErrorResult(addUserResult)); } trans.Commit(); Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); } catch (Exception ex) { trans.Rollback(); throw HandlerExceptions.GetInstance().RunCustomExceptions(ex); } } } }
public async Task <IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var user = new ApplicationUser() { UserName = createUserModel.Username, Email = createUserModel.Email, JoinDate = DateTime.Now.Date, }; IdentityResult addUserResult = await this.AppUserManager.CreateAsync(user, createUserModel.Password); if (!addUserResult.Succeeded) { return(GetErrorResult(addUserResult)); } var userEntity = this.AppUserManager.Users.FirstOrDefault(x => x.Email == createUserModel.Email); var newEmployeeId = _employeeService.Post(new EmployeeDto() { CompanyId = 1, Id = createUserModel.DeveloperId, Email = createUserModel.Email, FirstName = createUserModel.FirstName, Surname = createUserModel.LastName, }, userEntity); var readClaim = ExtendedClaimsProvider.CreateClaim("canReadUsers", "true"); var readProjectsClaim = ExtendedClaimsProvider.CreateClaim("canReadProjects", "true"); AppUserManager.AddClaim(userEntity.Id, readClaim); AppUserManager.AddClaim(userEntity.Id, readProjectsClaim); string code = await this.AppUserManager.GenerateEmailConfirmationTokenAsync(user.Id); var callbackUrl = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, code = HttpUtility.UrlEncode(code) })); try { await this.AppUserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking: " + callbackUrl); } catch (Exception ex) { return(BadRequest(ex.Message)); } Uri locationHeader = new Uri(Url.Link("GetUserById", new { id = user.Id })); return(Created(locationHeader, TheModelFactory.Create(user))); }
public IActionResult CreateUser([FromBody] CreateUserBindingModel model) { string buf = userHnd.CreateUser(model); if (!string.IsNullOrEmpty(buf)) { return(BadRequest(new { message = buf })); } return(Ok("\"success\"")); }
public GenericActionResult<UserReturnModel> CreateUser(CreateUserBindingModel user, string password) { var newUser = new ApplicationUser() { UserName = user.Email, Email = user.Email, FirstName = user.FirstName, LastName = user.LastName, PhoneNumber = user.MobileNumber }; IdentityResult addUserResult = this.Create(newUser, password); var result = new GenericActionResult<UserReturnModel>() { IsSuccess = addUserResult.Succeeded, Errors = addUserResult.Errors, Result = addUserResult.Succeeded ? _modelFactory.Create(newUser) : null }; return result; }
private string ValidateCreateModel(CreateUserBindingModel createModel, Role role) { string msg = String.Empty; if (role.Equals(Role.Affiliate)) { int category; if (!int.TryParse(createModel.UserCategory, out category)) { msg = "That is not a valid user category"; ModelState.AddModelError("createUserModel.UserCategory", msg); } } if (role.Equals(Role.Vendor)) { if (String.IsNullOrEmpty(createModel.ProgramDescription)) { msg = "Please enter a Program Description"; ModelState.AddModelError("createUserModel.ProgramDescription", msg); } if (String.IsNullOrEmpty(createModel.ProgramName)) { msg = "Please enter a Program Name"; ModelState.AddModelError("createUserModel.ProgramName", msg); } Program program = MarketManager.GetAllPrograms().Where(p => p.Name.ToLower() == createModel.ProgramName.ToLower()).FirstOrDefault(); if (null != program) { msg = "That program name is already taken, please enter something different"; ModelState.AddModelError("createUserModel.ProgramName", msg); } int category; if (!int.TryParse(createModel.ProgramCategory, out category)) { msg = "That is not a valid program category"; ModelState.AddModelError("createUserModel.ProgramCategory", msg); } if (String.IsNullOrEmpty(createModel.ProgramUrl)) { msg = "Please enter a Program Url"; ModelState.AddModelError("createUserModel.ProgramUrl", msg); } } return msg; }
public async Task<IHttpActionResult> CreateUser(CreateUserBindingModel createUserModel) { if (!ModelState.IsValid) { return BadRequest(ModelState); } bool IsMarketer = false; if (null != createUserModel.Marketer && !bool.TryParse(createUserModel.Marketer, out IsMarketer)) { return BadRequest(); } bool IsAffiliate = false; if (null != createUserModel.Affiliate && !bool.TryParse(createUserModel.Affiliate, out IsAffiliate)) { return BadRequest(); } if (!IsMarketer && !IsAffiliate) { return BadRequest("Affiliate or Marketer must be selected"); } if (IsAffiliate) { string error = ValidateCreateModel(createUserModel, Role.Affiliate); if (!String.IsNullOrEmpty(error)) { return BadRequest(ModelState); } } // check if the user created a program if (IsMarketer) { string error = ValidateCreateModel(createUserModel, Role.Vendor); if (!String.IsNullOrEmpty(error)) { 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); } // extend the user with specific information var userExt = new UserExtension() { SkypeHandle = createUserModel.SkypeHandle, UserId = user.Id, IndividualDescription = createUserModel.IndividualDescription, FirstName = createUserModel.FirstName, LastName = createUserModel.LastName, PhoneNumber = createUserModel.PhoneNumber, Category = Convert.ToInt32(createUserModel.UserCategory) }; UserExtManager.UserExtensions.Add(userExt); try { int resultCount = await UserExtManager.Update(); } catch (Exception ex) { // todo delete user here try { await AppUserManager.DeleteAsync(user); } catch { // do our best to not create secondary errors } return InternalServerError(); } // check if the user created a program if (IsMarketer) { AppUserManager.AddToRole(user.Id, "Vendor"); Program newProgram = new Program() { CreatedDate = DateTime.Now, CreatorId = user.Id, Description = createUserModel.ProgramDescription, Url = createUserModel.ProgramUrl, Name = createUserModel.ProgramName, Category = Convert.ToInt32(createUserModel.ProgramCategory) }; MarketManager.Programs.Add(newProgram); await MarketManager.Update(); } if (IsAffiliate) { AppUserManager.AddToRole(user.Id, "Affiliate"); } Uri locationHeader = await SendConfirm(user); return Created(locationHeader, TheModelFactory.Create(user, userExt)); }