//Post call for Login functionality
        public async Task <object> PostUserRegistrationDataAsync(UserRegistrationRequestModel loginRequest)
        {
            string requestUri = string.Empty; //= $"{Constant.BASE_URI}{Constant.LOGIN_API}";
            string jsonInput  = JsonConvert.SerializeObject(loginRequest);

            return(await PostDataAsync <UserRegistrationResponseModel>(new Uri(requestUri), jsonInput));
        }
예제 #2
0
        private async Task CreateAccount()
        {
            IsBusy = true;

            var user = new UserRegistrationRequestModel(
                StringUtils.RemoveWhiteSpaces(FormModelList[2].TextFieldValue),
                FormModelList[5].TextFieldValue,
                StringUtils.RemoveWhiteSpaces(FormModelList[0].TextFieldValue),
                StringUtils.RemoveWhiteSpaces(FormModelList[1].TextFieldValue),
                FormModelList[3].TextFieldValue
                );

            if (!CheckForm(user))
            {
                IsBusy = false;
                return;
            }

            user.FirstName = StringUtils.FirstCharToUpper(user.FirstName);
            user.LastName  = StringUtils.FirstCharToUpper(user.LastName);

            try
            {
                var result = await _authService.CreateAccount(user);

                if (result.StatusCode == 207)
                {
                    AppSettings.Logout();
                    _settingsService.Logout();
                    AppSettings.UserEmail = user.Email;
                    await SecureStorage.SetAsync("password", user.Password);

                    await NavigationService.NavigateAsync <LoginViewModel, object>(null);
                    await CloseView();

                    await NavigationService.NavigateAsync <ActivateAccountViewModel, string>(user.Email);

                    await Task.Delay(TimeSpan.FromSeconds(0.8f));

                    _dialogService.ShowAlert(_statusService.GetStatusCodeDescription(result.StatusCode), AlertType.Success, 8f);
                }
                else
                {
                    _dialogService.ShowAlert(_statusService.GetStatusCodeDescription(result.StatusCode), AlertType.Error);
                }
            }
            catch (Exception ex)
            {
                Ui.Handle(ex as dynamic);
            }
            finally
            {
                IsBusy = false;
            }
        }
예제 #3
0
        private User MapUserRequestModelToUserModel(UserRegistrationRequestModel oUserRequestModel)
        {
            User oUser = new Models.User();

            oUser.FirstName   = oUserRequestModel.first_name;
            oUser.LastName    = oUserRequestModel.last_name;
            oUser.PhoneNumber = oUserRequestModel.phone_number;
            oUser.Email       = oUserRequestModel.email_address;

            return(oUser);
        }
예제 #4
0
        public async Task <IdentityResult> Register(UserRegistrationRequestModel registrationRequest)
        {
            ApplicationUser applicationUser = new ApplicationUser()
            {
                Email     = registrationRequest.Email,
                UserName  = registrationRequest.Email,
                FirstName = registrationRequest.FirstName,
                LastName  = registrationRequest.LastName
            };

            return(await this._userManager.CreateAsync(applicationUser, registrationRequest.Password));
        }
예제 #5
0
        public async Task <IActionResult> Register([FromBody] UserRegistrationRequestModel model)
        {
            IdentityResult registrationResult = await this._authorizationService.Register(model);

            if (!registrationResult.Succeeded)
            {
                this.ModelState.AddIdentityErrors(registrationResult);
                return(this.BadRequest(this.ModelState));
            }

            return(this.StatusCode((int)HttpStatusCode.Created));
        }
예제 #6
0
        private bool CheckForm(UserRegistrationRequestModel user)
        {
            if (ReflectionHelper.HasEmptyOrNullValues(user))
            {
                _dialogService.ShowAlert(EmptyForm, AlertType.Error);
                return(false);
            }

            if (!StringUtils.CheckForEmojis(user.Password) || !StringUtils.CheckForEmojis(user.FirstName) || !StringUtils.CheckForEmojis(user.LastName))
            {
                _dialogService.ShowAlert(DamnEmojis, AlertType.Error, 6f);
                return(false);
            }

            if (!StringUtils.IsLettersOnly(user.FirstName) || !StringUtils.IsLettersOnly(user.LastName))
            {
                _dialogService.ShowAlert(InvalidString, AlertType.Error, 6.5f);
                return(false);
            }

            if (!EmailUtils.IsValidEmail(StringUtils.RemoveWhiteSpaces(user.Email)))
            {
                _dialogService.ShowAlert(InvalidEmail, AlertType.Error);
                return(false);
            }

            if (user.Password.Length < 8)
            {
                _dialogService.ShowAlert(PasswordWeak, AlertType.Error, 6f);
                return(false);
            }

            if (user.Password != FormModelList[4].TextFieldValue)
            {
                _dialogService.ShowAlert(PasswordMatch, AlertType.Error, 3.5f);
                return(false);
            }

            if (user.Phone.Length > 16 || user.Phone.Length < 8)
            {
                _dialogService.ShowAlert(AlertPhoneNumber, AlertType.Error, 3.5f);
                return(false);
            }

            if (!_userAgreed)
            {
                _dialogService.ShowAlert(UserAgreement, AlertType.Error);
                return(false);
            }

            return(true);
        }
예제 #7
0
        public async Task <IHttpActionResult> PostUser(UserRegistrationRequestModel oUserRequestModel)
        {
            string sIPAddress = Request.GetOwinContext().Request.RemoteIpAddress;

            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }

                bool blnIsEmailValid = ValidateEmailExists(oUserRequestModel.email_address);

                if (!blnIsEmailValid)
                {
                    return(BadRequest("E-mail address already exists"));
                }

                if (!oUserRequestModel.password.Equals(oUserRequestModel.password_confirm))
                {
                    return(BadRequest("Passwords Do not Match"));
                }

                if (!oUserRequestModel.password.Any(p => char.IsUpper(p)) && !oUserRequestModel.password_confirm.Any(cp => char.IsUpper(cp)))
                {
                    return(BadRequest("Passwords Don't Contain An Uppercase Letter"));
                }

                User user = oUserRegistration.CheckUserRegistration(oUserRequestModel);

                try
                {
                    await oUserRepo.SaveUser(user);

                    Auth0TokenReturnModel Auth0User = JsonConvert.DeserializeObject <Auth0TokenReturnModel>(oAuth0Users.CreateAuth0User(oUserRequestModel.email_address, oUserRequestModel.password));

                    user.EmailConfirmed  = Auth0User.email_verified;
                    user.Auth0Identifier = Auth0User.user_id;
                    user.CreationDate    = Convert.ToDateTime(Auth0User.created_at);

                    await oUserRepo.UpdateUserAfterRegistration(user);
                }
                catch (DbUpdateException)
                {
                    if (UserExists(user.Id))
                    {
                        return(Conflict());
                    }
                    else
                    {
                        return(InternalServerError());
                    }
                }

                return(CreatedAtRoute("DefaultApi", new { stripeCustId = user.StripeIdentifier }, user));
            }
            catch (Exception ex)
            {
                oLogger.LogData("ROUTE: api/Users; METHOD: POST; IP_ADDRESS: " + sIPAddress + "; EXCEPTION: " + ex.Message + "; INNER EXCEPTION: " + ex.InnerException);
                return(InternalServerError());
            }
        }
예제 #8
0
 public async Task <BaseModel> CreateAccount(UserRegistrationRequestModel userAccount)
 {
     return(await _webService.PostAsync <BaseModel>("registration/add", userAccount, needsHeaderCheck : false).ConfigureAwait(false));
 }
        public async Task <IHttpActionResult> Registration(UserRegistrationRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            try
            {
                var isUserExist = await userReadService.IsUserExistAsync(model.Email);

                if (isUserExist)
                {
                    return(BadRequest("User is already registered"));
                }
                else
                {
                    //registration
                    var chain = new Chain
                    {
                        CreatedOn = DateTime.UtcNow
                    };

                    var user = new User
                    {
                        Email            = model.Email,
                        Password         = userWriteService.HashPassword(model.Password),
                        Name             = model.Name,
                        Surname          = model.Surname,
                        Birthday         = model.Birthday,
                        LeagueId         = model.LeagueId,
                        RegistrationDate = DateTime.UtcNow,
                        Chain            = chain
                    };

                    var newUser = await userWriteService.RegistrationAsync(user);

                    //add history
                    var maxId = await chainReadService.GetMaxBlocksIdAsync();

                    var block = new HistoryBlock
                    {
                        Id        = ++maxId,
                        Changes   = "User registration",
                        AuthorId  = newUser.Id,
                        CreatedOn = DateTime.UtcNow.Date
                    };

                    block.Hash = block.HashValues();

                    var newBlock = await chainWriteService.AddHistoryBlockToChainAsync(newUser.Chain.Id, block);

                    //sign in
                    var identity = SignIn(newUser.Email, newUser.Role.Value, newUser.Id.ToString());

                    var token = GetUserToken(identity);

                    return(Ok(new { token, newUser.Id, newUser.RoleId }));
                }
            }
            catch (Exception ex)
            {
                return(InternalServerError(ex));
            }
        }