public async Task <ResponseModel> Post(AccountRegistrationModel model)
        {
            if (string.IsNullOrEmpty(model.Email))
            {
                return(ResponseModel.CreateInvalidFieldError("email", Phrases.FieldShouldNotBeEmpty));
            }

            if (!model.Email.IsValidEmail())
            {
                return(ResponseModel.CreateInvalidFieldError("email", Phrases.InvalidEmailFormat));
            }

            if (string.IsNullOrEmpty(model.FirstName))
            {
                return(ResponseModel.CreateInvalidFieldError("firstname", Phrases.FieldShouldNotBeEmpty));
            }

            if (string.IsNullOrEmpty(model.LastName))
            {
                return(ResponseModel.CreateInvalidFieldError("lastname", Phrases.FieldShouldNotBeEmpty));
            }

            if (string.IsNullOrEmpty(model.ContactPhone))
            {
                return(ResponseModel.CreateInvalidFieldError("contactphone", Phrases.FieldShouldNotBeEmpty));
            }

            if (await _clientAccountsRepository.IsTraderWithEmailExistsAsync(model.Email))
            {
                return(ResponseModel.CreateInvalidFieldError("email", Phrases.ClientWithEmailIsRegistered));
            }

            if (string.IsNullOrEmpty(model.Password))
            {
                return(ResponseModel.CreateInvalidFieldError("passowrd", Phrases.FieldShouldNotBeEmpty));
            }

            try
            {
                var user = await _srvClientManager.RegisterClientAsync(model.Email, model.FirstName, model.LastName, model.ContactPhone, model.Password);

                this.AuthenticateUserViaOwin(user);
                return(ResponseModel.CreateOk());
            }
            catch (Exception ex)
            {
                return(ResponseModel.CreateInvalidFieldError("email", ex.StackTrace));
            }
        }
示例#2
0
        public async Task <ActionResult> SignUp(SignUpModel model)
        {
            if (string.IsNullOrEmpty(model.Email))
            {
                return(this.JsonFailResult("#email", Phrases.FieldShouldNotBeEmpty));
            }

            if (!model.Email.IsValidEmail())
            {
                return(this.JsonFailResult("#email", Phrases.PleaseTypeEmailHere));
            }


            if (await _tradersRepository.IsTraderWithEmailExistsAsync(model.Email))
            {
                return(this.JsonFailResult("#email", Phrases.UserWithEmalExists));
            }

            if (string.IsNullOrEmpty(model.Password))
            {
                return(this.JsonFailResult("#password", Phrases.FieldShouldNotBeEmpty));
            }


            if (string.IsNullOrEmpty(model.PasswordAgain))
            {
                return(this.JsonFailResult("#passwordAgain", Phrases.FieldShouldNotBeEmpty));
            }

            if (model.Password != model.PasswordAgain)
            {
                return(this.JsonFailResult("#passwordAgain", Phrases.PasswordDoesNotMatch));
            }

            if (string.IsNullOrEmpty(model.Phone))
            {
                return(this.JsonFailResult("#phone", Phrases.FieldShouldNotBeEmpty));
            }

            var trader = await _srvClientManager.RegisterClientAsync(model.Email, model.FirstName, model.LastName, model.Password, model.Password);

            this.AuthenticateUserViaOwin(trader);

            return(GetAuthenticatedJsonResult());
        }