public async Task <ActionResult> Registration(RegistrationVm model) { if (!ModelState.IsValid) { return(View(model)); } UserDto user = _mapper.Map <RegistrationVm, UserDto>(model); OperationDetails details = await _userService.Registration(user); if (details.Succedeed) { var claim = await _userService.Login(model.UserName, model.Password); AuthenticationManager.SignOut(); AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = true }, claim); return(RedirectToAction("Index", "Home")); } else { ModelState.AddModelError(details.Property, details.Message); return(View(model)); } }
public async Task <IActionResult> Register([FromBody] RegistrationVm model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userIdentity = _mapper.Map <CustomUser>(model); var result = await _userManager.CreateAsync(userIdentity, model.Password); if (!result.Succeeded) { return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState))); } //await _appDbContext.JobSeekers.AddAsync(new JobSeeker { IdentityId = userIdentity.Id, Location = model.Location }); //await _appDbContext.SaveChangesAsync(); await _signInManager.SignInAsync(userIdentity, isPersistent : false); _logger.LogInformation(3, "User created a new account with password."); return(new OkObjectResult("Account created")); }
public async Task <ActionResult> SignUp(RegistrationVm registrationVm) { string messageRegistration = string.Empty; if (ModelState.IsValid) { //Login Verification var userDto = await Task.Run(() => _serviceFacade.UserService.Get.ByLogin(registrationVm.Login)); if (userDto != null) { ModelState.AddModelError("Warning key", "This login already exists"); } //Create user UserDto newUser = Mapper.Map <RegistrationVm, UserDto>(registrationVm); _serviceFacade.UserService.CreateAccount(newUser); MySocNetMembershipUser membershipUser = new MySocNetMembershipUser(newUser); SignIn(membershipUser); //redirecting return(JavaScript($"window.location = '{Url.Action("Settings", "User", new { id = membershipUser.UserId })}'")); } else { messageRegistration = "Не все поля заполнены корректно!"; } ViewBag.RegistrationErrorMessage = messageRegistration; return(View(registrationVm)); }
public IActionResult Register(RegistrationVm registrationModel) { if (ModelState.IsValid) { return(new RedirectToActionResult("RegistrationSuccess", "Users", null)); } else { return(View(registrationModel)); } }
public ActionResult Register() { var path = Server.MapPath("~/Content/UserProfile/"); var dir = new DirectoryInfo(path); var files = dir.EnumerateFiles().Select(f => f.Name); var viewModel = new RegistrationVm { Categories = _context.Countries.ToList(), Cities = _context.Cities.ToList(), Regiones = _context.Regionses.ToList(), Roles = _context.Roles.ToList(), FileName = files, User = new AspUser() }; return(View(viewModel)); }
public async Task <User> Register(RegistrationVm registration) { //TODO: Demonstrate fluent validation if (string.IsNullOrEmpty(registration.Email)) { throw new ApiException <string>("Email not provided"); } var user = new User { Email = registration.Email, Password = registration.Password, NameFirst = registration.NameFirst, NameLast = registration.NameLast }; return(await _userRepository.SaveAsync(user)); }
/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <exception cref="SwaggerException">A server side error occurred.</exception> public async System.Threading.Tasks.Task<LoginResultVm> RegisterAsync(RegistrationVm parameters = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { var urlBuilder_ = new System.Text.StringBuilder(); urlBuilder_.Append(BaseUrl).Append("/api/v1/Security/register"); var client_ = await CreateHttpClientAsync(cancellationToken).ConfigureAwait(false); try { using (var request_ = new System.Net.Http.HttpRequestMessage()) { var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(parameters, _settings.Value)); content_.Headers.ContentType.MediaType = "application/json"; request_.Content = content_; request_.Method = new System.Net.Http.HttpMethod("POST"); request_.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); PrepareRequest(client_, request_, urlBuilder_); var url_ = urlBuilder_.ToString(); request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute); PrepareRequest(client_, request_, url_); var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false); try { var headers_ = System.Linq.Enumerable.ToDictionary(response_.Headers, h_ => h_.Key, h_ => h_.Value); foreach (var item_ in response_.Content.Headers) headers_[item_.Key] = item_.Value; ProcessResponse(client_, response_); var status_ = ((int)response_.StatusCode).ToString(); if (status_ == "200") { var responseData_ = await response_.Content.ReadAsStringAsync().ConfigureAwait(false); var result_ = default(LoginResultVm); try { result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<LoginResultVm>(responseData_, _settings.Value); return result_; } catch (System.Exception exception) { throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, headers_, exception); } } else if (status_ == "400") { var responseData_ = await response_.Content.ReadAsStringAsync().ConfigureAwait(false); var result_ = default(object); try { result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<object>(responseData_, _settings.Value); } catch (System.Exception exception) { throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, headers_, exception); } throw new SwaggerException<object>("\nor\n", status_, responseData_, headers_, result_, null); } else if (status_ == "404") { var responseData_ = await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new SwaggerException("A server side error occurred.", status_, responseData_, headers_, null); } else if (status_ == "500") { var responseData_ = await response_.Content.ReadAsStringAsync().ConfigureAwait(false); var result_ = default(ApiError); try { result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<ApiError>(responseData_, _settings.Value); } catch (System.Exception exception) { throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, headers_, exception); } throw new SwaggerException<ApiError>("A server side error occurred.", status_, responseData_, headers_, result_, null); } else if (status_ != "200" && status_ != "204") { var responseData_ = await response_.Content.ReadAsStringAsync().ConfigureAwait(false); throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, headers_, null); } return default(LoginResultVm); } finally { if (response_ != null) response_.Dispose(); } } } finally { if (client_ != null) client_.Dispose(); } }
public ActionResult Register(RegistrationVm model) { try { if (!ModelState.IsValid) { var viewModel = new RegistrationVm() { //CatId = model.CatId, //CityId = model.CityId, //RegionId = model.RegionId, //RoleId = model.User.RoleId, //Categories = model.Categories, //Cities = model.Cities, //Regiones = model.Regiones, User = model.User, Roles = _context.Roles.ToList() }; return(View(viewModel)); } var addPath = Path.Combine(Server.MapPath("~/Content/UserProfile/"), model.File.FileName); var data = new byte[model.File.ContentLength]; model.File.InputStream.Read(data, 0, model.File.ContentLength); using (var sw = new FileStream(addPath, FileMode.Create)) { sw.Write(data, 0, data.Length); } int insertedRoleId = 2; if (model.User.RoleId == 0) { insertedRoleId = 2; } var newUser = new AspUser() { Name = model.User.Name, Email = model.User.Email, Password = Crypto.encrypt(model.User.Password), Image = model.File.FileName, Phone = model.User.Phone, RoleId = insertedRoleId }; // --------------------- Insert Data in User Table -------------------------- _context.Users.Add(newUser); _context.SaveChanges(); // --------------------- Insert Data in User_meta Table --------------------- // [Insert User Country] AspUserMeta obj = new AspUserMeta(); obj.UserId = newUser.Id; obj.ColName = "Country"; obj.Value = model.CatId.ToString(); _context.UsersMeta.Add(obj); _context.SaveChanges(); // [Insert User City] obj.UserId = newUser.Id; obj.ColName = "City"; obj.Value = model.CityId.ToString(); _context.UsersMeta.Add(obj); _context.SaveChanges(); // [Insert User Region] obj.UserId = newUser.Id; obj.ColName = "Region"; obj.Value = model.CityId.ToString(); _context.UsersMeta.Add(obj); _context.SaveChanges(); } catch (DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } return(RedirectToAction("Index")); }
public async Task <IActionResult> Register([FromBody] RegistrationVm parameters) { return(await ServiceInvoker.AsyncOk(async() => await _securityService.Register(parameters))); }