public UIElement GetRegisterElement() { ClientRegisterViewModel viewModel = new ClientRegisterViewModel(new ClientRegisterModel() { DateOfBirth = new DateTime(1990, 01, 01) }); RegisterClientControl control = new RegisterClientControl(viewModel); viewModel.ClientCreated += (s, e) => { ClientRegisterModel client = e.Client; ClientRegisterDTO clientDTO = Mapper.Map <ClientRegisterModel, ClientRegisterDTO>(client); using (IAccountService service = factory.CreateAccountService()) { ServiceMessage serviceMessage = service.Register(clientDTO); RaiseReceivedMessageEvent(serviceMessage); if (serviceMessage.IsSuccessful) { viewModel.FirstName = String.Empty; viewModel.LastName = String.Empty; viewModel.PhoneNumber = String.Empty; viewModel.Login = String.Empty; viewModel.Password = String.Empty; viewModel.ConfirmPassword = String.Empty; Notify(); } } }; return(control); }
private bool Validate(ClientRegisterDTO clientRegisterDTO, ref string message) { bool isValid = true; if (String.IsNullOrEmpty(clientRegisterDTO.LastName)) { message = "Last name must not be empty"; isValid = false; } else if (String.IsNullOrEmpty(clientRegisterDTO.FirstName)) { message = "First name must not be empty"; isValid = false; } else if (String.IsNullOrEmpty(clientRegisterDTO.PhoneNumber)) { message = "Phone number name must not be empty"; isValid = false; } else if (clientRegisterDTO.DateOfBirth.Year < DateTime.Now.Year - 100) { message = "You are too old. Sorry"; isValid = false; } else if (clientRegisterDTO.DateOfBirth.Year > DateTime.Now.Year - 18) { message = "You are too young. Sorry"; isValid = false; } return(isValid); }
public async Task <ClientRegisterResponseDTO> RegisterNewUser(ClientRegisterDTO registerInfo = null) { if (this._oAuthConsumer != null) { return(await this._oAuthConsumer.RegisterNewUser(registerInfo)); } return(null); }
public async Task RegisterAuthClient() { string url = ApiPaths.CLIENT_REGISTER_PATH; ClientRegisterDTO registerDTO = new ClientRegisterDTO() { Email = Helpers.RandomString(8) + GlobalConstants.AutoTestEmail, FullName = Helpers.RandomString(5) + " " + Helpers.RandomString(8), ContactPhone = Helpers.Random.Next(1000000, 9999999).ToString(), Password = Helpers.RandomString(10), Hint = Helpers.RandomString(3) }; string registerParam = JsonUtils.SerializeObject(registerDTO); var response = await this.Consumer.ExecuteRequest(url, Helpers.EmptyDictionary, registerParam, Method.POST); Assert.True(response.Status == System.Net.HttpStatusCode.OK); ClientDTO parsedResponse = JsonUtils.DeserializeJson <ClientDTO>(response.ResponseJson); PersonalDataEntity pdEntity = await this.PersonalDataRepository.TryGetAsync( p => p.PartitionKey == PersonalDataEntity.GeneratePartitionKey() && p.Email == registerDTO.Email.ToLower()) as PersonalDataEntity; Assert.NotNull(pdEntity); Assert.True(pdEntity.ContactPhone == registerDTO.ContactPhone); Assert.True(pdEntity.FullName == registerDTO.FullName); Assert.True(pdEntity.PasswordHint == registerDTO.Hint); TradersEntity traderEntity = await this.TradersRepository.TryGetAsync( t => t.PartitionKey == "Trader" && t.Id == pdEntity.RowKey ) as TradersEntity; Assert.NotNull(traderEntity); TradersEntity traderEmailEntity = await this.TradersRepository.TryGetAsync( t => t.PartitionKey == "IndexEmail" && t.Id == registerDTO.Email && t.PrimaryRowKey == pdEntity.RowKey ) as TradersEntity; Assert.NotNull(traderEmailEntity); //Authentication User newUser = new User() { Email = registerDTO.Email, Password = registerDTO.Password }; string userParam = JsonUtils.SerializeObject(newUser); string authUrl = ApiPaths.CLIENT_BASE_PATH + "/auth"; var authResponse = await this.Consumer.ExecuteRequest(authUrl, Helpers.EmptyDictionary, userParam, Method.POST); Assert.True(authResponse.Status == HttpStatusCode.OK); }
public async Task <IActionResult> SignUp([FromBody] ClientRegisterDTO client) { if (client == null || !TryValidateModel(client)) { return(BadRequest(ModelState)); } if (await clientService.ClientExistsAsync(client.Phone)) { return(BadRequest("User with such phone number already exists")); } string apiKey = await clientService.SignUpAsync(client); if (apiKey != null) { return(Created("", apiKey)); } return(NotFound()); }
public async Task <string> SignUpAsync(ClientRegisterDTO clientData) { int code = clientData.Code; Client client = Mapper.Map <ClientRegisterDTO, Client>(clientData); SMSCode sms = await db.SMSCodes.FirstOrDefaultAsync(s => s.Phone == client.Phone && s.Code == code); if (sms == null) { return(null); } await db.SMSCodes.RemoveAsync(sms); string apiKey = encrypt.GenerateHash(client.Phone, code.ToString()); client.ApiKey = apiKey; await db.Clients.CreateAsync(client); return(apiKey); }
/// <summary> /// Registers new user. If another user was inputted via one of the constructors it will be overwritten. /// </summary> /// <param name="registrationInfo"></param> /// <returns></returns> public async Task <ClientRegisterResponseDTO> RegisterNewUser(ClientRegisterDTO registrationInfo = null) { var regClient = new RestClient(BaseRegisterUrl); var regRequest = new RestRequest(RegisterPath, Method.POST); ClientRegisterDTO registerDTO = registrationInfo ?? new ClientRegisterDTO() { Email = Helpers.RandomString(8) + GlobalConstants.AutoTestEmail, FullName = Helpers.RandomString(5) + " " + Helpers.RandomString(8), ContactPhone = Helpers.Random.Next(1000000, 9999999).ToString(), Password = Helpers.RandomString(10), Hint = Helpers.RandomString(3) }; string registerParam = JsonUtils.SerializeObject(registerDTO); regRequest.AddParameter("application/json", registerParam, ParameterType.RequestBody); var regResponse = await regClient.ExecuteAsync(regRequest); if (regResponse.StatusCode == HttpStatusCode.OK) { ClientRegisterResponseDTO parsedRegResponse = JsonUtils.DeserializeJson <ClientRegisterResponseDTO>(regResponse.Content); this.AuthUser = new User() { Email = registerDTO.Email, Password = registerDTO.Password }; this.ClientInfo = parsedRegResponse; await this.Authenticate(); return(parsedRegResponse); } return(null); }
public override ServiceMessage Register(ClientRegisterDTO clientRegisterDTO) { string message = ""; bool success = true; if (!Validate(clientRegisterDTO, ref message)) { success = false; } else if (!registerValidator.Validate(clientRegisterDTO, ref message)) { success = false; } else { string hashedPassword = encryptor.Encrypt(clientRegisterDTO.Password); try { IEnumerable <string> logins = unitOfWork.Users.GetAll().Select(user => user.Login); if (!logins.Contains(clientRegisterDTO.Login)) { bool phoneNumberExists = unitOfWork.Clients.GetAll().Any(c => c.PhoneNumber == clientRegisterDTO.PhoneNumber); if (!phoneNumberExists) { unitOfWork.Accounts.RegisterClientRole(clientRegisterDTO.Login, hashedPassword); UserEntity userEntity = new UserEntity { Login = clientRegisterDTO.Login, Role = unitOfWork.Roles.Get(RolesCodes.ClientRole) }; unitOfWork.Users.Add(userEntity); unitOfWork.Commit(); ClientEntity clientEntity = new ClientEntity { Id = userEntity.Id, FirstName = clientRegisterDTO.FirstName, LastName = clientRegisterDTO.LastName, PhoneNumber = clientRegisterDTO.PhoneNumber, DateOfBirth = clientRegisterDTO.DateOfBirth, DateOfRegistration = DateTime.Now }; unitOfWork.Clients.Add(clientEntity); unitOfWork.Commit(); message = "Registered new client"; } else { success = false; message = "Such phone number already exists. Try another one"; } } else { success = false; message = "Such login already exists. Try another one"; } } catch (Exception ex) { message = ExceptionMessageBuilder.BuildMessage(ex); success = false; } } return(new ServiceMessage(message, success)); }
public virtual ServiceMessage Register(ClientRegisterDTO clientRegisterDTO) { return(new ServiceMessage("No permissions to register clients", false)); }