Example #1
0
        public async Task <ActionResult> Create(CreateUserViewModel userViewModel)
        {//TODO Upload Profile image
            var newUser = userViewModel.CurrentUser;

            newUser.ProfileImagePath = "Default";
            newUser.UserTypeID       = (int)UserType.UserTypes.User;

            if (ModelState.IsValid)
            {
                if (_userManger.UserNameExists(userViewModel.CurrentUser.UserName))
                {
                    ViewBag.Message             = "Username is currently being used";
                    userViewModel.Genders       = _genderManager.GetAll();
                    userViewModel.Nationalities = _nationalityManager.GetAll();

                    return(View(nameof(Create), userViewModel));
                }
                else
                {
                    await _userManger.Add(newUser, userViewModel.Password);

                    var user = _userManger.Login(newUser.UserName, userViewModel.Password);

                    if (!(user is InvalidUser))
                    {
                        _sessionHelper.Add("CurrentUser", user);
                        return(RedirectToAction(nameof(EditIntegrations)));
                    }
                }
            }

            ViewBag.Message = "An error occurred when creating the account.";
            return(View(nameof(Create)));
        }
Example #2
0
        public ActionResult Login(LoginModel login)
        {
            User user;

            user = _usermanager.Login(login.Username, login.Password);
            if (!(user is InvalidUser))
            {
                _sessionHelper.Add("CurrentUser", user);
                return(RedirectToAction("Index", "Home"));
            }

            ViewBag.Message = "Invalid Username or Password";
            return(View(nameof(login)));
        }