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 } })); } }
public async Task <User> registerUser(UserRegisterInput input) { using (NpgsqlConnection connection = new NpgsqlConnection(_config.GetConnectionString("postgres"))) { if (await _isEmailTaken(input.email, connection)) { throw new ArgumentException("Email is already taken"); } else { //salt and hash passwords byte[] salt = new byte[16]; new RNGCryptoServiceProvider().GetBytes(salt); Rfc2898DeriveBytes generator = new Rfc2898DeriveBytes(input.password, salt); byte[] hash = generator.GetBytes(16); //password hash has the salt from 0-15 and the hash result from 16-31 byte[] passwordhash = new byte[32]; Array.Copy(salt, 0, passwordhash, 0, 16); Array.Copy(hash, 0, passwordhash, 16, 16); //store in db string sql = "INSERT INTO \"user\" (email,password) VALUES( @email,@password) RETURNING*"; User result = await connection.QueryFirstOrDefaultAsync <User>(sql, new { email = input.email, password = Convert.ToBase64String(passwordhash) }); return(result); } } }
public async Task <ApiResult> Register([FromBody] UserRegisterInput input) { ApiResult result = new ApiResult(); var cacheVerifycode = await cacheManager.GetCache(AbpCacheNames.SMS_Verify_Code).GetOrDefaultAsync <string, VerifyCodeCacheItem>(input.PhoneNumber); if (input.VerifyCode != "00") { if (cacheVerifycode == null || cacheVerifycode.VerifyCode != input.VerifyCode) { result.success = false; result.message = "验证码过期或者无效"; return(result); } } var user = Mapper.Map <UserInfo>(input); user.UserName = input.PhoneNumber; var identityResult = await userManager.CreateAsync(user, input.Password); if (!identityResult.Succeeded) { result.success = false; result.message = string.Join(Consts.ERROR_SPLIT, identityResult.Errors.Select(x => x.Description)); } return(result); }
public async Task <ApiResult> RegisterAsync(UserRegisterInput userRegisterInput) { userRegisterInput.Password = Md5Crypt.Encrypt(userRegisterInput.Password); var userModel = _mapper.Map <User>(userRegisterInput); userModel.CreateTime = DateTime.Now; userModel.Ip = _accessor.HttpContext.Request.Headers["X-Forwarded-For"].FirstOrDefault() ?? _accessor.HttpContext.Connection.RemoteIpAddress.ToString(); userModel.Address = IpParse.GetAddressByIP(userModel.Ip); var i = await AddAsync(userModel); return(new ApiResult(i)); }
public async Task <IActionResult> Register(UserRegisterInput input) { var existingUser = await Mongo.GetUserByEmail(input.Email); if (existingUser != null) { return(this.ProblemParameter("Supplied email address is already registered")); } if (!CheckPassword(input.Password)) { return(this.ProblemParameter("Password is not secure")); } var verificationToken = new Random().GenerateReadableCode(8); Logger.LogDebug("Registering new user for {0} with verification token {1}", input.Email, verificationToken); try { var user = new User { Email = input.Email, PasswordHash = BCrypt.Net.BCrypt.HashPassword(input.Password), Name = input.Name, Surname = input.Surname, VerificationToken = verificationToken, RegisteredOn = DateTime.UtcNow }; await Mongo.CreateUser(user); _composer.SendVerificationMail(user); return(CreatedAtAction( nameof(GetInformation), new { id = user.Id.ToString() }, new UserOutput { Id = user.Id.ToString(), Email = user.Email, Name = user.Name, Surname = user.Surname } )); } catch (Exception ex) { Logger.LogError(ex, "Failed to register new user with email {0}", input.Email); throw; } }
public Task <IActionResult> Post([FromBody] UserRegisterInput input) { return(Task.Run <IActionResult>(() => { if (!ModelState.IsValid) { Console.WriteLine(input); return BadRequest(); } var user = _db.Single <User>(u => u.Username == input.Username.ToLower()); if (user != null) { return new StatusCodeResult((int)HttpStatusCode.Conflict); } if (!ValidatePassword(input.Password)) { return BadRequest(new { Message = "Password not valid" }); } try { var hashedPassword = BCrypt.Net.BCrypt.HashPassword(input.Password); user = new User { Username = input.Username.ToLower(), Password = hashedPassword, RoleId = input.RoleId, IsActive = input?.IsActive ?? false, Validated = input?.Validated ?? false }; _db.Add(user); return Ok(new { success = true, userId = user.Id }); } catch (Exception) { return new StatusCodeResult((int)HttpStatusCode.InternalServerError); } })); }
/// <summary> /// 用户注册 /// </summary> /// <param name="input"></param> /// <returns></returns> public async Task <UserRegisterOutput> UserRegister(UserRegisterInput input) { //input dto -> business obj var user = input.Map2User(AbpSession.GetTenantId()); //用户注册 var result = await _userDomainService.UserRegister(user); //business obj -> output dto var dtoItem = Mapper.Map <IdentityResultDto>(result); return(new UserRegisterOutput { Result = dtoItem, UserId = user.Id }); }
public static KuhmunityResponse Register( string apiUrl, UserRegisterInput kuhmunityProfileData) { KuhmunityResponse response = new KuhmunityResponse { IsSuccessful = false }; using (var client = new WebClient()) { try { var data = JsonConvert.SerializeObject(kuhmunityProfileData); client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); var apiResponse = client.UploadString(new Uri(apiUrl + "Register?output=json"), "POST", data); if (!string.IsNullOrWhiteSpace(apiResponse)) { var receivedData = JsonConvert.DeserializeObject <UserResultDTO>(apiResponse); if (receivedData.Status.Equals("OK")) { response.IsSuccessful = true; response.Body = receivedData.UserId; } else { response.Message = receivedData.Status; } } return(response); } catch (Exception ex) { response.Message = ResponseMessages.SERVER_ERROR; response.ErrorMessage = ex.Message; return(response); } } }
public UserLoginOutput UserRegister(UserRegisterInput input) { UserLoginOutput output = new UserLoginOutput(); //if (string.IsNullOrEmpty(model.RoleId)) //{ // output.Message = "请选择一个角色!"; // return output; //} if (string.IsNullOrEmpty(input.UserName)) { output.Message = "登录用户名不能为空!"; return(output); } if (Utils.GetStringLength(input.UserName.Trim()) < 5) { output.Message = "登录用户名不能小于5个字节!"; return(output); } if (string.IsNullOrEmpty(input.Password)) { output.Message = "密码不能为空!"; return(output); } if (input.Password.Length < 5) { output.Message = "密码不能小于5个字符!"; return(output); } switch (input.Type) { case RegisterType.Email: //valid Email if (!Utils.IsValidEmail(input.UserName)) { output.Message = "邮件格式不正确!"; return(output); } break; case RegisterType.Mobile: if (!Utils.IsMobile(input.UserName)) { output.Message = "手机号码不正确!"; return(output); } break; case RegisterType.QQ: break; case RegisterType.WeiXin: break; default: break; } //验证用户名 if (IsExistUser(input.OrgId, input.UserName)) { output.Message = "该用户名已经存在,请选择其他用户名!"; return(output); } User user = new User(); user.UserName = input.UserName; user.Salt = Utils.GetRandomChar(10); user.Password = Utils.MD5(user.Salt + input.Password); user.OrgId = input.OrgId; user.RType = input.Type; if (!string.IsNullOrEmpty(input.RoleId)) { user.RoleId = input.RoleId; } else { //注册用户 var role = _roleRepository.Single(a => a.OrgId == input.OrgId && a.Name == "注册用户"); if (role != null) { user.RoleId = role.Id; } } user.ActiveCode = Guid.NewGuid().ToString("N"); var result = _userRepository.AddUser(user); AddUserLog(user.OrgId, PublicModuleNames.UserModule, OperationType.Add, input.Url); output.LoginAccount = result; if (!string.IsNullOrEmpty(user.RoleId)) { output.LoginRole = _roleRepository.GetById(user.RoleId); } try { switch (input.Type) { case RegisterType.Email: user.Email = input.UserName; _userRepository.Update(user); _emailService.SendActiveEmail(input.OrgId, result.Id); break; case RegisterType.Mobile: break; } } catch (Exception ex) { output.Message = ex.Message; return(output); } return(output); }
public async Task <ApiResult> Register([FromBody] UserRegisterInput userRegisterInput) { return(await _userService.RegisterAsync(userRegisterInput)); }
public KuhmunityRegistrationModule(IConfiguration configuration, UserRegisterInput kuhmunityData) { _kuhmunityProfileData = kuhmunityData; _configuration = configuration; }
public KuhmunityRegistrationModule(UserRegisterInput kuhmunityData) { _kuhmunityProfileData = kuhmunityData; }