public IActionResult Register(int Category, string ShopName, string fullname, string Mobile, string UserName, string Password, string RePassword) { RequestRegisterUserDto requestRegisterUser = new RequestRegisterUserDto() { Email = UserName + "@msn.com", FullName = fullname, Password = Password, ConfirmPassword = RePassword, UserName = UserName, Role = "Seller" }; var resultRegister = _registerUserService.Execute(requestRegisterUser); if (resultRegister.Data.IdentityResult.Succeeded == true) { RequestAddNewSellerDto request = new RequestAddNewSellerDto() { UserName = UserName, CategoryId = Category, Mobile = Mobile, ShopName = ShopName, UserId = resultRegister.Data.UserId, }; return(Json(_sellerService.Add(request))); } else { return(Json(resultRegister.Message)); } }
public virtual async Task <IActionResult> Register([FromBody] UserDto userDto) { userDto = await _registerUserService.Execute(userDto); //userDto = await _sendEmailConfirmationService.Execute(userDto); return(Ok(new ResponseDto("success", userDto))); }
public async Task Execute(Input input) { if (input == null) { _outputHandler.Error("Input is null."); return; } var isEmailExist = await _registerUserService.GetEmailUser(input.Email.ToString()); var isPhoneExist = _registerUserService.GetMobileUser(input.Mobile.ToString()).Result; var isUserNameExist = await _registerUserService.GetNameUser(input.Name.ToString()); if (isEmailExist != null) { _outputHandler.Error("Email Already Exist"); } else if (isPhoneExist != null) { _outputHandler.Error("MobileNumber Already Exist"); } else if (isUserNameExist != null) { _outputHandler.Error("UserName Already Exist"); } //var customerId = _registerUserService.Execute(input.Name.ToString(), input.Password.ToString()); //add //if (customerId == null || customerId == Guid.Empty) //add else if (isEmailExist == null && isPhoneExist == null && isUserNameExist == null) { var registerOutput = _registerUserService.Execute(input.Name.ToString(), input.Password.ToString() , input.Email.ToString(), input.Mobile.ToString()); if (registerOutput == null) { _outputHandler.Error("An error throw when registering user ID"); //add return; //add } var customer = _entityFactory.NewCustomer(registerOutput.CustomerId, input.SSN, input.Name); var account = _entityFactory.NewAccount(customer.Id); ICredit credit = account.Deposit(input.InitialAmount); if (credit == null) { _outputHandler.Error("An error happened when depositing the amount."); return; } customer.Register(account.Id); await _customerRepository.Add(customer); await _accountRepository.Add(account, credit); Output output = new Output(customer, account, registerOutput.Token); _outputHandler.Handle(output); } }
public ActionResult Create(string Str_FullName, string Str_Email, int int_RoleId, string Str_Password, string Str_RePassword) { var result = _registerUserService.Execute(new RequestRegisterUserDto() { FullName = Str_FullName, Email = Str_Email, //Roles = new List<RolesInRegisterUserDto>() //{ // new RolesInRegisterUserDto // { // RoleId=int_RoleId // } //}, Password = Str_Password, ConfirmPassword = Str_RePassword }); return(View(result)); }
public async Task Execute(Input input) { if (input == null) { _outputHandler.Error("Input is null."); return; } var registerOutput = _registerUserService.Execute(input.Name.ToString(), input.Password.ToString()); if (registerOutput == null) { _outputHandler.Error("An error throw when registering user ID"); return; } var customer = _entityFactory.NewCustomer(registerOutput.CustomerId, input.SSN, input.Name); var account = _entityFactory.NewAccount(customer.Id); ICredit credit = account.Deposit(input.InitialAmount); if (credit == null) { _outputHandler.Error("An error happened when depositing the amount."); return; } customer.Register(account.Id); await _customerRepository.Add(customer); await _accountRepository.Add(account, credit); Output output = new Output(customer, account, registerOutput.Token); _outputHandler.Handle(output); }
public IActionResult Signup(RequestRegisterUserDto request) { #region validate if (string.IsNullOrWhiteSpace(request.FullName) || string.IsNullOrWhiteSpace(request.Email) || string.IsNullOrWhiteSpace(request.Password) || string.IsNullOrWhiteSpace(request.ConfirmPassword)) { return(Json(new ResultDto { IsSuccess = false, Message = "لطفا تمامی موارد رو ارسال نمایید" })); } if (User.Identity.IsAuthenticated == true) { return(Json(new ResultDto { IsSuccess = false, Message = "شما به حساب کاربری خود وارد شده اید! و در حال حاضر نمیتوانید ثبت نام مجدد نمایید" })); } if (request.Password != request.ConfirmPassword) { return(Json(new ResultDto { IsSuccess = false, Message = "رمز عبور و تکرار آن برابر نیست" })); } if (request.Password.Length < 8) { return(Json(new ResultDto { IsSuccess = false, Message = "رمز عبور باید حداقل 8 کاراکتر باشد" })); } string emailRegex = @"^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[A-Z0-9.-]+\.[A-Z]{2,}$"; var match = Regex.Match(request.Email, emailRegex, RegexOptions.IgnoreCase); if (!match.Success) { return(Json(new ResultDto { IsSuccess = true, Message = "ایمیل خودرا به درستی وارد نمایید" })); } #endregion var signupResult = _registerUserService.Execute(new RequestRegisterUserDto { UserName = request.Email, Email = request.Email, FullName = request.FullName, Password = request.Password, ConfirmPassword = request.ConfirmPassword, Role = "Customer", }); if (signupResult.Data.IdentityResult.Succeeded) { string CallBackUrl = Url.Action("ConfirmEmail", "Authentication", new { UserId = signupResult.Data.UserId, token = signupResult.Data.token }, protocol: Request.Scheme); string Body = $"لطفا برای فعالسازی کاربری خود بر روی لینک زیر کلیک کنید <br/> <a href={CallBackUrl}>Link</a>"; _emailService.Execute(request.Email, Body, "فعال سازی نام کاربری"); //return RedirectToAction("DisplayEmail"); return(Json(new ResultDto() { IsSuccess = true, Message = $"!ثبت نام با موفقیت انجام شد<br/>لینک فعالسازی به ایمیل شما ارسال شد" })); } //string message = ""; //foreach (var item in signupResult.Data.IdentityResult.Errors.ToList()) //{ // message += item.Description + Environment.NewLine; //} //return View( new ResultDto() //{ // Message = message, //}); if (signupResult.Data.IdentityResult.Succeeded) { var claims = new List <Claim>() { new Claim(ClaimTypes.NameIdentifier, signupResult.Data.UserId), new Claim(ClaimTypes.Email, request.Email), new Claim(ClaimTypes.Name, request.FullName), new Claim(ClaimTypes.Role, "Customer"), }; var identity = new ClaimsIdentity(claims, CookieAuthenticationDefaults.AuthenticationScheme); var principal = new ClaimsPrincipal(identity); var properties = new AuthenticationProperties() { IsPersistent = true }; HttpContext.SignInAsync(principal, properties); } return(Json(signupResult)); }