Beispiel #1
0
 public async Task <BaseApiDataModel <Guid?> > Create(CreateAccountRequestModel accountModel)
 {
     return(await Execute(async() =>
     {
         var account = await _accountService.CreateAccount(accountModel.UserName, accountModel.Password, new List <Guid>());
         return account?.Id;
     }));
 }
Beispiel #2
0
        public async Task <ActionResult> CreateAccountAsync([FromBody] CreateAccountRequestModel accountModel)
        {
            if (!Guid.TryParse(accountModel.StoreBranchId, out var storeBranchId))
            {
                return(BadRequest());
            }
            if (!Guid.TryParse(accountModel.InvestmentToolId, out var investmentToolId))
            {
                return(BadRequest());
            }

            var account = new Account(storeBranchId, accountModel.AccountTypeId, investmentToolId,
                                      accountModel.AccountNo, accountModel.AccountName);

            _accountRepository.Add(account);
            await _accountRepository.UnitOfWork.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetByIdAsync), new { id = account.Id }, null));
        }
Beispiel #3
0
        public async Task <CreateAccountResponseModel> Post(CreateAccountRequestModel model)
        {
            CreateAccountResponseModel responseModel = new CreateAccountResponseModel();

            try
            {
                string token = _configuration.GetSection("Auth0").GetSection("Token").Value;
                string url   = _configuration.GetSection("Auth0").GetSection("Url").Value;
                Dictionary <string, string> metadata = new Dictionary <string, string>();
                metadata.Add("DeviceID", model.DeviceId);

                using var client = new ManagementApiClient(token, new Uri(url));
                var response = await client.Users.CreateAsync(new UserCreateRequest
                {
                    Connection   = "Username-Password-Authentication",
                    Email        = model.Email,
                    Password     = model.Password,
                    FirstName    = model.FirstName,
                    LastName     = model.LastName,
                    UserMetadata = metadata
                });

                if (!String.IsNullOrEmpty(response.UserId))
                {
                    responseModel.IsSuccess    = true;
                    responseModel.ErrorMessage = string.Empty;
                    responseModel.UserId       = response.UserId;
                }
                else
                {
                    responseModel.ErrorMessage = "Failed to create new user";
                }
            }
            catch (Exception ex)
            {
                responseModel.IsSuccess    = false;
                responseModel.ErrorMessage = ex.InnerException != null ? ex.InnerException.Message : ex.Message;
                _logger.LogError(ex.ToString());
            }

            return(responseModel);
        }
        public JsonResult CreateAccount(CreateAccountRequestModel model)
        {
            bool invalidUsername = false;
            bool invalidPassword = false;
            bool invalidEmailAdd = false;
            bool invalidEmailCon = false;

            string usernameResponse = "Good";
            string passwordResponse = "Good";
            string emailAddResponse = "Good";
            string repeatEmResponse = "Good";

            if (string.IsNullOrEmpty(model.Username) || model.Username.Length < 6)
            {
                usernameResponse = "Invalid";
                invalidUsername  = true;
            }
            else if (accountExists(model.Username))
            {
                usernameResponse = "Exists";
                invalidUsername  = true;
            }

            if (string.IsNullOrEmpty(model.Password) || model.Password.Length < 6)
            {
                passwordResponse = "Invalid";
                invalidPassword  = true;
            }

            if (string.IsNullOrEmpty(model.EmailAdd) || !model.EmailAdd.Contains("@"))
            {
                emailAddResponse = "Invalid";
                invalidEmailAdd  = true;
            }

            if (string.IsNullOrEmpty(model.EmailCon))
            {
                repeatEmResponse = "Invalid";
                invalidEmailCon  = true;
            }
            else if (!model.EmailAdd.Equals(model.EmailCon))
            {
                repeatEmResponse = "Mismatch";
                invalidEmailCon  = true;
            }

            if (invalidUsername || invalidPassword || invalidEmailAdd || invalidEmailCon)
            {
                return(new JsonResult().SerializeObject(new
                {
                    Message = "Error",
                    Username = usernameResponse,
                    Password = passwordResponse,
                    EmailAdd = emailAddResponse,
                    EmailCon = repeatEmResponse
                }));
            }

            createAccount(model.Username, model.Password, model.EmailAdd);

            return(new JsonResult().SerializeObject(new
            {
                Message = "Success"
            }));
        }
        public async Task <ResponseModelBase> CreateAccount([FromBody] CreateAccountRequestModel model)
        {
            if (!ModelState.IsValid)
            {
                return(ErrorModel.Of("invalid_request"));
            }

            var um = new UserModel();

            um.AccountCreationDate    = DateTime.UtcNow;
            um.EmailAddress           = model.EmailAddress;
            um.UniqueConfirmationCode = Guid.NewGuid();
            um.EmailConfirmationSent  = DateTime.UtcNow;
            um.PasswordHashes         = PasswordHasher.GenerateHashPermutations(model.Password);
            um.UniqueId = Guid.NewGuid();
            um.Username = model.Username.Trim();

            //And validate the email address
            if (!EmailAddressVerifier.IsValidEmail(model.EmailAddress)) //valid address
            {
                return(ErrorModel.Of("email_invalid"));
            }
            if (await ldb.FindByEmailAddress(model.EmailAddress) != null) //in use
            {
                return(ErrorModel.Of("email_in_use"));
            }
            //Username
            if (await ldb.FindByUsername(model.Username) != null) //also in use
            {
                return(ErrorModel.Of("username_in_use"));
            }
            if (um.Username.Length < 5)
            {
                return(ErrorModel.Of("username_invalid"));
            }
            if (!new Regex(@"[a-zA-Z0-9\s_-]").IsMatch(um.Username))
            {
                return(ErrorModel.Of("username_invalid"));
            }
            //Password
            if (model.Password.ToLower().Contains("password"))
            {
                return(ErrorModel.Of("password_too_simple"));
            }
            if (model.Password.ToLower().StartsWith("1234"))
            {
                return(ErrorModel.Of("password_too_simple"));
            }
            if (model.Password.Length < 8)
            {
                return(ErrorModel.Of("password_too_short"));
            }
            //And check the question/answer section
            if (!AccountTests.ValidateChallenge(model.ChallengeId, model.ChallengeAnswer))
            {
                return(ErrorModel.Of("validation_incorrect"));
            }

            //Send the registration email
            await EmailSender.SendEmail(um, EmailSender.RegistrationTemplate);

            //Save user in the DB
            await ldb.AddUser(um);

            return(Models.OkModel.Of("account_created"));
        }