public async Task <ActionResult <UserRegisterResponse> > Register(UserRegisterInput _input) { try{ User insertedUser = await userService.registerUser(_input); string token = await userService.login(new UserLoginInput { email = _input.email, password = _input.password }); UserRegisterResponse response = new UserRegisterResponse { isSuccess = true, payload = new UserRegisterResponseData { token = token, user = insertedUser } }; return(Ok(response)); }catch (UnauthorizedAccessException ex) { return(Unauthorized(new UserRegisterResponse { error = new ApiError { msg = ex.Message } })); }catch (Exception ex) { return(BadRequest(new UserRegisterResponse { error = new ApiError { msg = ex.Message } })); } }
void OnUserRegister(object sender, UserRegisterResponse response) { if (this.OnRegister != null) { this.OnRegister(response.Result, response.Errormsg); } }
public ActionResult <UserRegisterResponse> Post([FromBody] UserRegisterRequest request) { try { // Validate user input if (ModelState.IsValid) { Validation validation = new Validation(request.UserName, request.Email, request.UserPassword); if (validation.methodOfResponse == GlobalParmeters.RESPONSE_SERVERERROR) { return(StatusCode(StatusCodes.Status500InternalServerError)); } else if (validation.methodOfResponse == GlobalParmeters.RESPONSE_USERERROR) { return(BadRequest(validation.errorMsg)); } else { UserRegisterResponse response = DAL.Register(request.UserName, request.FirstName, request.LastName, request.Email, request.UserPassword); return(CreatedAtRoute("Get", new { id = response.UserName }, response)); } } else { return(BadRequest(ModelState)); } } catch (Exception ee) { //should be a server side error response (5XXX) return(BadRequest(ee)); } }
void OnUserRegister(object sender, UserRegisterResponse response) { Debug.LogFormat("OnUserRegister:{0} [{1}]", response.Result, response.Errormsg); if (this.OnRegister != null) { this.OnRegister(response.Result, response.Errormsg); } }
public UserRegisterResponse CreateUserRegistered(User user) { var userRegistered = new UserRegisterResponse { Data = CreateDto(user) }; return(userRegistered); }
public async Task <object> Register([FromBody] UserRegister userRegister) { if (!ModelState.IsValid) { return(BadRequest(ModelState.Values.SelectMany(start => start.Errors).Select(error => error.ErrorMessage).Take(1).ElementAt(0))); } // Google Recaptcha Validation if (WebConfigurationManager.AppSettings["GoogleRecaptcha"] == "true") { GoogleResponse googleResponse = await _google.ValidateRecaptcha <GoogleResponse>(userRegister.Token); if (!googleResponse.Success) { return(BadRequest("error.validation.invalid-recaptcha")); } } // HCaptcha Validation if (WebConfigurationManager.AppSettings["HCaptcha"] == "true") { HCaptchaResponse hCaptchaResponse = await _hCaptcha.Validate <HCaptchaResponse>(userRegister.Token); if (!hCaptchaResponse.Success) { return(BadRequest("error.validation.invalid-hcaptcha")); } } UserRegisterResponse user = await _userService.Register(userRegister); if (user.ErrorEmail) { return(BadRequest("error.user.email-exists")); } if (user.ErrorCpf) { return(BadRequest("error.user.cpf-exists")); } // Register Mail if (WebConfigurationManager.AppSettings["Mail"] == "true") { string message = RenderRazor.RenderView("~/Views/MailTemplates/Register.cshtml", userRegister, null); MailService.SendMailAsync(userRegister.Email, new string[] { }, "Register", message); } return(Ok(user)); }
/// <summary> /// 注册金生金账户 /// </summary> /// <param name="certificate">用户证件类型:身份证1,机构代码2,营业执照3 </param> /// <param name="accountLoginId">用户证件号</param> /// <param name="pwd">没加密的密码</param> /// <param name="agency">代理商名称</param> /// <param name="category">用户类型</param> /// <param name="username">真实姓名</param> /// <param name="tel">手机</param> /// <returns>1000表示用户已经存在,2000表示系统错误,guid表示注册成功,返回用户主键</returns> public string JgjUserRegister(int certificate, string accountLoginId, string pwd, string agency, int category, string userName, string tel) { UserRegisterRequest request = new UserRegisterRequest(); request.Body = new UserRegisterRequestBody(); request.Body.accountLoginId = accountLoginId; request.Body.certificate = certificate; request.Body.pwd = pwd; request.Body.agency = agency; request.Body.category = category; request.Body.username = userName; request.Body.tel = tel; UserRegisterResponse res = _JgjServiceSoapClient.UserRegister(request); return(res.Body.UserRegisterResult); // return _JgjServiceSoapClient.UserRegister(certificate, accountLoginId, pwd, agency, category, userName, tel); }
public ApiResponse ShortCode([FromBody] UserRegister model) { string shortCode = "1234"; var options = new MemoryCacheEntryOptions { AbsoluteExpirationRelativeToNow = TimeSpan.FromSeconds(300) }; _cache.Set(model.Mobile, shortCode, options); var result = new UserRegisterResponse { ShortCode = shortCode }; return(new ApiResponse("success", result, StatusCodes.Status200OK)); }
public async Task <UserRegisterResponse> RegisterAsync(UserRegisterRequest request) { User user = await _userRepository.GetUserByEmailAsync(request.Email); if (user != null) { throw new Exception($"O e-mail {request.Email} já está cadastrado."); } user = (User)request; user.Id = Guid.NewGuid(); var result = await _userRepository.SaveAsync(user); await _userRepository.SaveChangesAsync(); UserRegisterResponse response = (UserRegisterResponse)result; return(response); }
/// <summary> /// 用户注册 /// </summary> /// <param name="userName"></param> /// <param name="password"></param> /// <param name="code"></param> /// <param name="sale"></param> /// <returns></returns> public string Register(string userName, string password, string code, string sale, out string message) { string resultToken = ""; message = ""; try { string apiName = "user"; UserRegisterRequest user = new UserRegisterRequest() { username = userName, password = password, code = code }; if (!string.IsNullOrEmpty(sale)) { user.sale = sale; } string json = JsonConvert.SerializeObject(user); string resultStr = HttpHelper.HttpUrlSend(apiName, "POST", json); CommonResponse resultResponse = JsonConvert.DeserializeObject <CommonResponse>(resultStr); if (resultResponse.state) { UserRegisterResponse resultInfo = JsonConvert.DeserializeObject <UserRegisterResponse>(resultResponse.result); resultToken = resultInfo.sessionToken; } else { message = resultResponse.message; } } catch (Exception ex) { message = "注册用户失败"; WPFClientCheckWordUtil.Log.TextLog.SaveError(ex.Message); } return(resultToken); }
public async Task <UserRegisterResponse> Register(string email) { var exist = (await _userRepository.FindByAsync(u => string.Equals(u.Email, email.ToLowerInvariant()))) .FirstOrDefault(); if (!(exist is null)) { return(UserRegisterResponse.Error("Podany adres email, został już zarejestrowany w systemie")); } try { var guid = Guid.NewGuid().ToString().ToUpperInvariant(); var newUserId = await _userRepository.CreateAsync( new User { Email = email, Guid = guid }); if (newUserId > 0) { var emailUI = new EmailUI(guid); var emailToSend = emailUI.Prepare(); if (emailUI.CanBeSend) { var emailToUser = _emailNotification.Send( emailToSend.Title, emailToSend.RawMessage, emailToSend.HtmlMessage, new string[] { email }); if (emailToUser.IsSuccess) { var msg = $"Utworzono użytkownika: {email} i wysłano wiadomość."; _logger.LogInformation(msg); _pushOverNotification.Send("[PewneMieszkanie.pl] - Sukces", msg); return(UserRegisterResponse.Success()); } else { _logger.LogInformation(emailToUser.Message); _pushOverNotification.Send("[PewneMieszkanie.pl] - Błąd", emailToUser.Message); return(UserRegisterResponse.Error(emailToUser.Message)); } } else { return(UserRegisterResponse.Error($"Wiadomość do {email} nie może zostać wysłana.")); } } else { var msg = $"Błąd przy tworzeniu użytkownika - {email}."; _logger.LogError(msg); return(UserRegisterResponse.Error(msg)); } } catch (Exception ex) { _logger.LogCritical(ex.GetFullMessage()); return(UserRegisterResponse.Error(ex.GetFullMessage())); } }
/// <summary> /// Register the specified userRegister. /// </summary> /// <returns>The register.</returns> /// <param name="userRegister">User register.</param> public async Task <UserRegisterResponse> Register(UserRegister userRegister) { // Register response UserRegisterResponse userRegisterResponse = new UserRegisterResponse(); // Check if user email exists User[] checkUserEmail = await(from u in db.Users where u.Email == userRegister.Email select u).Take(1).ToArrayAsync(); if (checkUserEmail.Any()) { userRegisterResponse.ErrorEmail = true; return(userRegisterResponse); } // Check if user cpf exists User[] checkUserCpf = await(from u in db.Users where u.Cpf == userRegister.Cpf select u).Take(1).ToArrayAsync(); if (checkUserCpf.Any()) { userRegisterResponse.ErrorCpf = true; return(userRegisterResponse); } // Default Normal User Role ID int roleId = 1; // Save User User user = new User { FirstName = userRegister.FirstName, LastName = userRegister.LastName, Email = userRegister.Email, AcceptReleases = userRegister.AcceptReleases, Password = new HashPassword().Generate(userRegister.Password), StateID = userRegister.StateID, CityID = userRegister.CityID, Cpf = userRegister.Cpf, Cnpj = userRegister.Cnpj, RoleID = roleId, CreatedAt = DateTime.Now }; db.Users.Add(user); await db.SaveChangesAsync(); // Save Log int userId = int.Parse(Thread.CurrentPrincipal.Identity.Name); Log log = new Log { UserID = userId, Action = "user.register" }; await new LogService().Save(log); // User Token Claim[] claims = { new Claim(ClaimTypes.Name, userRegister.FirstName), new Claim(ClaimTypes.Email, userRegister.Email), new Claim(ClaimTypes.Role, roleId.ToString()) }; userRegisterResponse.TokenType = "Bearer"; userRegisterResponse.AccessToken = _tokenManager.Generate(claims); return(userRegisterResponse); }