public async Task <bool> CreateNewUser(String mail, String name, String passwd) //TaskCompletedDelegate delegateResult, { var userSignUpRequest = new UserSignUpRequest { User = new UserRequest() { Email = mail, //"*****@*****.**", FullName = name, Password = passwd } }; var response = await _quickbloxClient.UsersClient.SignUpUserAsync(userSignUpRequest); // (userSignUpRequest); //Console.WriteLine(response.StatusCode); if (response.StatusCode == HttpStatusCode.Created) { sUserID = response.Result.User.Id.ToString(); return(true); } else { sUserID = ""; return(false); } }
/// <summary> /// API User sign up. Use for the identification of the mobile applications users. The request can contain all, some or none of the optional parameters. /// Login, email, facebook ID, twitter ID and the external user ID should not be taken previously. /// If you want to create a user with a some content (f.e. with a photo) you have to create a blob firstly. /// The same tags can be used for any number of users. /// </summary> /// <returns></returns> public async Task <HttpResponse <UserResponse> > SignUpUserAsync(UserSignUpRequest userSignUpRequest) { var headers = RequestHeadersBuilder.GetDefaultHeaders().GetHeaderWithQbToken(this.quickbloxClient.Token); return(await HttpService.PostAsync <UserResponse, UserSignUpRequest>(this.quickbloxClient.ApiEndPoint, QuickbloxMethods.UsersMethod, userSignUpRequest, headers)); }
public override async Task <User> Create(UserSignUpRequest request, ServerCallContext context) { var user = _mapper.Map <User>(request); if (string.IsNullOrWhiteSpace(request.Password)) { throw new ArgumentException("Password Hash is required"); } if (_context.Users.Any(x => x.UserName == request.UserName)) { throw new ArgumentException("UserName \"" + request.UserName + "\" is already taken"); } CreatePasswordHash(request.Password, out var passwordHash, out var passwordSalt); user.PasswordHash = Convert.ToBase64String(passwordHash); user.PasswordSalt = ByteString.CopyFrom(passwordSalt); var originUser = _mapper.Map <DAL.Models.User>(user); await _context.Users.AddAsync(originUser); await _context.SaveChangesAsync(); return(user); }
public async Task <ResponseMessage <UserJson> > SignUp([FromBody] UserSignUpRequest request) { // 日志输出:请求体 Console.WriteLine("WS------ Request: \r\n" + JsonUtil.ToJson(request)); // 创建响应体 ResponseMessage <UserJson> response = new ResponseMessage <UserJson>(); // 模型验证 if (!Util.ModelValidCheck(ModelState, response)) { return(response); } try { // 业务处理 await Manager.Create(response, request, default(CancellationToken)); } catch (Exception e) { Def.Response.Wrap(response, ResponseDefine.ServiceError, e.Message); // 日志输出:服务器错误 Console.WriteLine("WS------ ServiceError: \r\n" + e); } // 日志输出:响应体 Console.WriteLine("WS------ Response: \r\n" + response != null ? JsonUtil.ToJson(response) : ""); return(response); }
public async Task <AuthStatusResponse> SignUpAsync(UserSignUpRequest request, User user) { User userExists = await authRepository.GetUserAsync(user); if (userExists != null) { return new AuthStatusResponse { Status = false, Message = "Unauthorized.", Token = null, User = null } } ; user.AvatarImage = await fileService.StoreImage(config.GetSection("UsersImages").Value, request.AvatarImage); User newAddedUser = await authRepository.AddAsync(user); if (newAddedUser == null) { return new AuthStatusResponse { Status = false, Message = "Signing up failed.", Token = null, User = null } } ; string token = tokenService.GenerateToken(user); UserResponse userResponse = mapper.Map <User, UserResponse>(newAddedUser); return(new AuthStatusResponse { Status = true, Message = "Successful signing up", Token = token, User = userResponse }); } } }
public async Task <AuthenticationResponse> Register(UserSignUpRequest userSignUpRequest) { var newUser = new User() { Email = userSignUpRequest.Email, UserName = userSignUpRequest.Email, FirstName = userSignUpRequest.FirstName, LastName = userSignUpRequest.LastName }; var createdUserResult = await _userManager.CreateAsync(newUser, userSignUpRequest.Password); if (!createdUserResult.Succeeded) { return(new AuthenticationResponse() { Success = false, ErrorMessages = createdUserResult.Errors.Select(e => e.Description) }); } var addedRoleResult = await _userManager.AddToRoleAsync(newUser, "User"); if (!addedRoleResult.Succeeded) { return(new AuthenticationResponse() { Success = false, ErrorMessages = addedRoleResult.Errors.Select(e => e.Description) }); } return(await GenerateAuthenticationResponseWithTokenAsync(newUser)); }
public void ShouldSignUpUser() { UserSignUpRequest request = CreateRequest(); userRepository .Setup(x => x.Exist(request.Email)) .Returns(false); var passwordSalt = new Password.Salt(value: "4235346654"); securePseudoRandomGenerator .Setup(x => x.Generate()) .Returns(passwordSalt); var hashedPasswordOutput = "$2y$asdasdVDFJVw4rtfAFVSDfjc34t"; hashingService .Setup(x => x.Hash(request.Password.Value + passwordSalt.Value)) .Returns(hashedPasswordOutput); var result = command.Execute(request); Assert.IsTrue(result.IsValid); userRepository .Verify(x => x.Create(It.Is <SaltedPasswordHashing.Src.Domain.User.User>(x => x.IdProp.Value != null && x.Email.Value == request.Email.Value && x.Password.Value == hashedPasswordOutput && x.Password.SaltProp.Value == passwordSalt.Value)), Times.Once()); }
/// <summary> /// 用户注册 /// </summary> /// <param name="response"></param> /// <param name="request"></param> /// <param name="cancellationToken"></param> /// <returns></returns> public async Task Create([Required] ResponseMessage <UserJson> response, [Required] UserSignUpRequest request, CancellationToken cancellationToken = default(CancellationToken)) { // 检查参数是否异常 var signupUserJson = request.SignupUser; // 不采用request.User的原因是为了后台手动注册时也有账户登陆 if (signupUserJson == null || signupUserJson.Name == null || signupUserJson.Pwd == null) { Def.Response.Wrap(response, ResponseDefine.BadRequset, "用户注册信息不全"); return; } // 检查用户是否已经存在 var dbuser = TheUsers.ByName(signupUserJson.Name).SingleOrDefault(); if (dbuser != null) { Def.Response.Wrap(response, ResponseDefine.BadRequset, "该用户名已经存在,不能重复注册,若是你注册的请登陆或到密码找回处找回密码"); return; } // 创建用户 dbuser = _Mapper.Map <User>(signupUserJson); dbuser.Id = Guid.NewGuid().ToString(); dbuser._CreateUserId = dbuser.Id; var user = await TheUsers.CreateAsync(dbuser, cancellationToken); if (user == null) { Def.Response.Wrap(response, ResponseDefine.ServiceError, "在数据库插入数据失败"); return; } response.Extension = _Mapper.Map <UserJson>(user); }
private UserSignUpRequest CreateRequest() { return(UserSignUpRequest.Create( email: "*****@*****.**", password: "******" ).Result); }
public async Task <ActionResult <UserSignUpResponse> > SignUpManager([FromBody] UserSignUpRequest request) { if (!ModelState.IsValid) { return(BadRequest()); } var result = await _registrationService.RegisterManagerAsync(request.Email, request.Password); var response = new UserSignUpResponse { Email = request.Email, Role = ApplicationRoles.Manager, IsRegistrationSuccessful = result }; if (result) { return(response); } response.ResponseException = "Not successful registration. Check logs"; return(response); }
public UserSimpleResponse SignUpUser(UserSignUpRequest userSignUpRequest) { var user = mapper.Map <User>(userSignUpRequest); _users.Add(user); return(mapper.Map <UserSimpleResponse>(_users.SingleOrDefault(u => u.Id == user.Id))); }
public async Task <IActionResult> SignUpAsync(UserSignUpRequest model) { var authenticationResult = await _userService.CreateAsync(model); return(!authenticationResult.Result ? BadRequest(new { message = authenticationResult.Message }) : NoContent()); }
public static UserSignUpValue ToUserValueSignUp(this UserSignUpRequest request) => new UserSignUpValue { Email = request.Email, Password = request.Password, UserDocument = request.UserDocument.Replace("-", string.Empty).Replace(".", string.Empty), UserName = request.UserName, UserId = Guid.NewGuid(), SignUpDate = DateTime.UtcNow };
public void ShouldReturnsErrorWhenCreationIsFail() { RequestValidationResult <UserSignUpRequest, Error> result = UserSignUpRequest.Create( email: "*****@*****.**", password: string.Empty ); Assert.IsFalse(result.IsValid); Assert.AreEqual(result.Errors.First().FieldId, "Password"); Assert.AreEqual(result.Errors.First().Error, Error.Required); }
public IActionResult SignUp(UserSignUpRequest userSignUpRequest) { var user = userService.SignUpUser(userSignUpRequest); if (user == null) { return(NotFound()); } return(Ok(user)); }
public async Task <IActionResult> SignUp(UserSignUpRequest userSignUpRequest) { var result = await _identityService.Register(userSignUpRequest); if (result.Success) { return(Created(string.Empty, result)); } return(BadRequest(result.ErrorMessages)); }
public async Task <ActionResult> SignUpAsync([FromForm] UserSignUpRequest request) { User user = mapper.Map <UserSignUpRequest, User>(request); AuthStatusResponse response = await authService.SignUpAsync(request, user); if (response.Status) { return(Ok(response)); } return(BadRequest(new ErrorResponse { Error = response.Message, Status = response.Status })); }
public void ShouldCreatesValidSignUpRequest() { var email = "*****@*****.**"; var password = "******"; RequestValidationResult <UserSignUpRequest, Error> result = UserSignUpRequest.Create( email: email, password: password ); Assert.IsTrue(result.IsValid); Assert.AreEqual(result.Result.Email.Value, email); Assert.AreEqual(result.Result.Password.Value, password); }
public async Task <bool> SignUp(UserSignUpFormModel form) { var request = new UserSignUpRequest { FirstName = form.FirstName, LastName = form.LastName, Email = form.Email, Password = form.Password, PasswordConfirmation = form.PasswordConfirmation }; var response = await signUpServiceClient.UserSignUpAsync(request); return(response.Status == ResponseStatus.Ok); }
public async Task <IActionResult> Register(UserSignUpRequest user) { try { var identityUser = new User { FirstName = user.FirstName, UserName = user.Email, Email = user.Email, IsStockProvider = user.IsStockProvider }; return(Ok(await _userManager.CreateAsync(identityUser, user.Password))); } catch (Exception e) { Console.WriteLine(e); return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task SignUpUserSuccess() { UserSignUpRequest userSignUpRequest = new UserSignUpRequest() { User = new UserRequest() { Login = "******", Password = "******", Email = "*****@*****.**" } }; var response = await this.client.UsersClient.SignUpUserAsync(userSignUpRequest); Assert.IsTrue(response.StatusCode == HttpStatusCode.Created); // login is aready taken }
public async Task<User> SignUpUserWithLoginAsync(string login, string password, string userName, string roomName) { UserSignUpRequest request = new UserSignUpRequest(); request.User = new UserRequest(); request.User.Login = login; request.User.Password = password; request.User.FullName = userName; request.User.TagList = roomName; var signUpResponse = await this.client.UsersClient.SignUpUserAsync(request); if (await HandleResponse(signUpResponse, HttpStatusCode.Created)) { return signUpResponse.Result.User; } return null; }
public void ShouldReturnErrorWhenUserAlreadyExist() { UserSignUpRequest request = CreateRequest(); userRepository .Setup(x => x.Exist(request.Email)) .Returns(true); var result = command.Execute(request); Assert.IsFalse(result.IsValid); Assert.AreEqual(result.Error, SignUpError.UserAlreadyExist); securePseudoRandomGenerator .Verify(x => x.Generate(), Times.Never()); hashingService .Verify(x => x.Hash(It.IsAny <string>()), Times.Never()); userRepository .Verify(x => x.Create(It.IsAny <SaltedPasswordHashing.Src.Domain.User.User>()), Times.Never()); }
public async Task <User> SignUpUserWithLoginAsync(string login, string password, string userName, string roomName) { UserSignUpRequest request = new UserSignUpRequest(); request.User = new UserRequest(); request.User.Login = login; request.User.Password = password; request.User.FullName = userName; request.User.TagList = roomName; var signUpResponse = await this.client.UsersClient.SignUpUserAsync(request); if (await HandleResponse(signUpResponse, HttpStatusCode.Created)) { return(signUpResponse.Result.User); } return(null); }
public async Task <AuthenticationResult> CreateAsync(UserSignUpRequest model) { var lastUserId = (await _userStoreManager.GetAllAsync()) .LastOrDefault().Id; await _userStoreManager.AddAsync(new User { Id = ++lastUserId, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, Username = Guid.NewGuid().ToString(), Password = model.Password, }); return(new AuthenticationResult { Result = true, Message = "User created successfully", }); }
public async Task <BaseResponse> Notify(UserSignUpRequest request) { var response = new BaseResponse(); try { var valueObject = request.ToUserValueSignUp(); var signUpDoesNotExist = await _repository.SingUpInsert(valueObject); if (signUpDoesNotExist) { await _publisher.Execute(valueObject); } } catch (Exception e) { _logger.LogError(e, "UserSignUpNotification Error"); response.ResponseType = ResponseTypeEnum.Error; } return(response); }
public void Execute(SignUpRequestDto request) { var userSignUpRequestCreationResult = UserSignUpRequest.Create( email: request.Email, password: request.Password ); if (!userSignUpRequestCreationResult.IsValid) { PrintErrors(); } else { ExecuteCommand(); } void PrintErrors() { foreach (var error in userSignUpRequestCreationResult.Errors) { consoleLogger.LogInfo(error.FieldId); consoleLogger.LogInfo(error.Error.ToString()); } } void ExecuteCommand() { var request = userSignUpRequestCreationResult.Result; var commandResult = command.Execute(request); if (!commandResult.IsValid) { consoleLogger.LogInfo(commandResult.Error.ToString()); } else { consoleLogger.LogInfo("User registered successfuly!"); } } }
public async Task <UserResponse> UserSignUp(UserSignUpRequest request) { LogUtil.Error("UserSignUp in UserController : " + request.StudyId + ", " + request.Password); UserResponse response = await Task.Run(() => _userService.UserSignUp(request)); if (response != null && response.ErrorCode == LAMPConstants.API_SUCCESS_CODE) { UserSessionToken tokenObj = _authService.CreateSessionTokenObject(response.UserId, response.Email, response.StudyId); if (tokenObj.ErrorCode == LAMPConstants.API_SUCCESS_CODE) { response.SessionToken = tokenObj.SessionToken; } else { response = new UserResponse { ErrorCode = LAMPConstants.API_SESSION_TOKEN_UPDATION_FAILED, ErrorMessage = ResourceHelper.GetStringResource(LAMPConstants.API_SESSION_TOKEN_UPDATION_FAILED) }; } } return(response); }
public async Task <ActionResult <UserSignUpResponse> > SignUp([FromBody] UserSignUpRequest request) { _logger.LogInformation($"{nameof(SignUpIdentityController)}: Registration request with email = {request.Email}"); var result = await _registrationService.RegisterDefaultUserAsync(request.Email, request.Password); if (!result) { _logger.LogInformation($"{nameof(SignUpIdentityController)}: Registration request with email = {request.Email}. Registration service sent an error"); return(new UserSignUpResponse { Email = request.Email, IsRegistrationSuccessful = false, ResponseException = $"User with email {request.Email} is already exists or may be there another problem. Try another email" }); } _logger.LogInformation($"{nameof(SignUpIdentityController)}: successful registration for user with email = {request.Email}"); var token = new JwtUserToken(_jwtConfiguration) { Email = request.Email, Role = ApplicationRoles.DefaultUser }; return(new UserSignUpResponse { Email = request.Email, IsRegistrationSuccessful = true, ResponseException = null, Role = ApplicationRoles.DefaultUser, JwtToken = token.GetToken() }); }
public void Handle(UserSignUpRequest request) { emailer.SendRegistrationConfirmation("me", "username", "blah"); }
private async void SignUpCommandExecute() { if (string.IsNullOrWhiteSpace(FullName) || string.IsNullOrWhiteSpace(Email) || string.IsNullOrWhiteSpace(Password)) { await messageService.ShowAsync("Message", "Please fill all empty input fields"); return; } if (!Helpers.IsInternetConnected()) { await messageService.ShowAsync("Connection failed", "Please check your internet connection."); return; } IsLoading = true; await CreateSession(); var userSignUpRequest = new UserSignUpRequest { User = new UserRequest() { Email = email, FullName = fullName, Password = password } }; var response = await QuickbloxClient.UsersClient.SignUpUserAsync(userSignUpRequest); if (response.StatusCode == HttpStatusCode.Created) { int? userId = await Login(); if (userId != null) { if (userImageBytes != null) await UploadUserImage(response.Result.User, userImageBytes); NavigationService.Navigate(ViewLocator.Main, new DialogsNavigationParameter { CurrentUserId = userId.Value, Password = Password }); } } else await Helpers.ShowErrors(response.Errors, messageService); IsLoading = false; }
public UserSignUpResponse UserSignUp([FromBody] UserSignUpRequest req) { var time = DateTime.Now; var rep = new UserSignUpResponse(); if (!req.Mobile.IsMobile()) { rep.Error("请输入正确的手机号码"); return(rep); } if (!req.Pwd.IsPassword()) { rep.Error("密码为6-18个字符(至少包含两个字母、两个数字、一个特殊字符)"); return(rep); } var valid = ValidateSmsCaptcha(req.Guid, req.Mobile, req.Captcha); if (!valid) { rep.Error("短信验证码不正确或已过期"); return(rep); } var userId = DefaultStorage.UserIdGet(req.Uid); if (userId > 0) { rep.Error("该手机号码已被使用,请换一个"); return(rep); } var pwd = req.Pwd; var user = new User(); var profile = new UserProfile(); //var extra = new UserExtra(); user.Guid = Guid.NewGuid().ToString(); user.Name = req.Uid; user.Email = string.Empty; user.Mobile = req.Mobile; user.Nickname = string.Empty; user.Password = pwd; user.Role = UserRole.Buyer; user.Grade = UserGrade.None; user.Limitation = UserLimitation.None; user.Permission = UserPermission.None; user.Avatar = string.Empty; user.Status = UserStatus.Normal; user.AuthedOn = null; user.CreatedBy = string.Empty; user.CreatedOn = time; user.ModifiedBy = string.Empty; user.ModifiedOn = time; profile.Code = string.Empty; profile.Name = string.Empty; profile.Gender = Gender.Secrect; profile.Marital = Marital.Secrect; profile.Birthday = null; profile.Phone = string.Empty; profile.Mobile = string.Empty; profile.RegionId = string.Empty; profile.Street = string.Empty; profile.SignUpIp = string.Empty; profile.SignUpBy = 1; profile.TraceCode = ""; profile.LastSignInIp = string.Empty; profile.LastSignInOn = time; user.Profile = profile; //user.Extra = extra; var id = DefaultStorage.UserCreate(user); if (id > 0) { rep.Data = DefaultStorage.UserGet(id); } else { rep.Error("注册失败,请稍后再试"); return(rep); } return(rep); }
public async Task <BaseResponse> SignUp([FromBody] UserSignUpRequest request) { return(await _userSignUp.Notify(request)); }