Exemplo n.º 1
0
        private void AfterAccessNotification(TokenCacheNotificationArgs args)
        {
            // if state changed
            if (HasStateChanged)
            {
                // check for an existing entry
                _userAccount = _userAccountService.FetchByUsername(_userName);

                if (_userAccount == null)
                {
                    // Create the account
                    _userAccountService.Create(new CreateUserAccountModel()
                    {
                        Firstname  = "",
                        Lastname   = "",
                        Username   = _userName,
                        CachedData = Serialize(),
                        UpdateDate = DateTime.Now
                    });
                }
                else
                {
                    // Update the account
                    _userAccount.CachedData = this.Serialize();
                    _userAccount.UpdateDate = DateTime.Now;

                    _userAccountService.UpdateCacheData(_userAccount);
                }

                HasStateChanged = false;
            }
        }
        public ActionResult Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                //make sure email/username is unique
                if (!_UserService.IsUsernameUnique(model.Email))
                {
                    ModelState.AddModelError("", "There is already an account with that email.");
                    return(View(model));
                }

                var user = new BankApi.Models.UserAccount()
                {
                    Email = model.Email, Password = model.Password
                };

                if (_UserService.Create(user))
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
        //public IActionResult SignUp(string username, string password)
        public IActionResult SignUp(UserAccount ua)
        {
            if (ModelState.IsValid)
            {
                if (_service.Create(ua))
                {
                    HttpContext.Session.SetString("username", ua.UserName);
                }
                ModelState.AddModelError("UserName", "Username already taken!");
            }

            return(View("Login"));
        }
Exemplo n.º 4
0
        public async Task <IActionResult> CreateAccount([FromBody] CreateAccountModel createAccount)
        {
            //nts if this should go to a fluent validation thing...
            if (string.IsNullOrEmpty(createAccount.Email))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("email")));
            }
            if (string.IsNullOrEmpty(createAccount.FullName))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("fullname")));
            }
            if (string.IsNullOrEmpty(createAccount.Login))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("login")));
            }
            if (string.IsNullOrEmpty(createAccount.Password))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("password")));
            }

            var inviteCode = default(Guid);

            if (!Guid.TryParse(createAccount.InvitationCode, out inviteCode))
            {
                return(BadRequest(BistroFiftyTwoError.MissingField("invitationCode")));
            }

            // for now do the stupid, just hard code the inivite code.
            if (inviteCode != Guid.Parse(Configuration["InvitationCode"]))
            {
                return(BadRequest(BistroFiftyTwoError.Invalid("invitationCode", createAccount.InvitationCode)));
            }

            var newUserAccount = new UserAccount
            {
                Email           = createAccount.Email,
                Fullname        = createAccount.FullName,
                UserLogin       = createAccount.Login,
                AccountPassword = createAccount.Password
            };

            var existingAccount = await UserAccountService.GetByLogin(newUserAccount.UserLogin);

            if (existingAccount != null)
            {
                return(BadRequest(new BistroFiftyTwoError
                {
                    FieldName = "login",
                    ErrorType = "duplicate",
                    Description = $"{createAccount.Login} is already taken.  Please choose another login name"
                }));
            }

            var userAccount = await UserAccountService.Create(newUserAccount);

            await RoleService.GrantDefaultRoles(userAccount.ID);

            var securedAccount = new SecuredUserAccount
            {
                Email      = userAccount.Email,
                Fullname   = userAccount.Fullname,
                ID         = userAccount.ID,
                IsDisabled = userAccount.IsDisabled,
                IsLocked   = userAccount.IsLocked,
                UserLogin  = userAccount.UserLogin
            };

            return(Created($"api/accounts/{userAccount.ID}", securedAccount));
        }
Exemplo n.º 5
0
 public bool Create(UserAccount user)
 {
     return(UserAccountService.Create(user));
 }
        //[HttpPost]
        public ActionResult <UserAccount> Create(UserAccount account)
        {
            accountService.Create(account);

            return(CreatedAtRoute("GetAccount", new { id = account.UserAccountID.ToString() }, account));
        }