示例#1
0
        public async Task <IActionResult> SignUp([FromBody] SignInModel signinModel)
        {
            if (accountsRepository.IsAccountExists(signinModel.Account.UserName))
            {
                return(BadRequest(accountExistsError));
            }

            if (!HasValidPassword(signinModel.Password))
            {
                return(BadRequest(weakPasswordError));
            }
            var addedAccount = new Account();

            try
            {
                addedAccount = await accountsRepository.AddAccount(signinModel.Account, signinModel.Password);
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
            var returnAccount = new
            {
                addedAccount.EntityId,
                addedAccount.Name,
                addedAccount.Surname,
                addedAccount.Address,
                addedAccount.UserName,
                addedAccount.Role
            };

            return(Ok(returnAccount));
        }
示例#2
0
        public async Task <CallBackUrl> Register(string email, string password)
        {
            if (!Validate.EmailValidation(email))
            {
                throw new ValidationException("Invalid inputs");
            }

            if (!Validate.PasswordValidation(password))
            {
                throw new ValidationException("Invalid inputs");
            }

            ApplicationUser user = new ApplicationUser {
                UserName = email, Email = email
            };
            IdentityResult result = await _userManager.CreateAsync(user, password);

            if (result.Succeeded)
            {
                try
                {
                    _accountsRepository.AddAccount(GuidBuilder.Create().ToString(), user.Id);
                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
                    // Send an email with this link
                    string code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    string callbackUrl = Url.Action("ConfirmEmail", "Profile", new { userId = user.Id, code = code }, protocol: HttpContext.Request.Scheme);
                    await _emailSender.SendEmailAsync(email, "Please confirm your email address",
                                                      $"Please confirm your account by clicking this link: <a href='{callbackUrl}'>link</a> or by entering this code in the app: " + code);

                    return(new CallBackUrl()
                    {
                        Url = callbackUrl
                    });
                }
                catch (Exception ex)
                {
                    await _userManager.DeleteAsync(user);

                    throw new ValidationException("Could not create user:"******"Could not create user");
            }
        }
        public void CreateNewAccount(MemberLoginDetails details)
        {
            if (_accounts.AccountExists(details.UserName))
            {
                throw new Exception("Account already exists");
            }

            string salt = _hasher.GetNewSalt();

            Account account = new Account()
            {
                DateCreated = DateTime.Now,
                UserName    = details.UserName,
                Password    = _hasher.SaltedPassword(details.Password, salt),
                Salt        = salt
            };

            _accounts.AddAccount(account);
        }
示例#4
0
        private async Task <Account> GetUser()
        {
            var user = EntitiesCreationService.GetUser();

            return(await accountsRepository.AddAccount(user, "password"));
        }
示例#5
0
 public void Post([FromBody] AccountModel account)
 {
     _repository.AddAccount(account);
 }