Exemple #1
0
        public ActionResult Register(RegisterViewModel login)
        {
            if (!ModelState.IsValid)
            {
                return(View(login));
            }

            if (IsUserExist(login))
            {
                ViewBag.message = "Already Existing User ...";
                ModelState.AddModelError("Error", "Already Existing User ...");
                return(View(login));
            }

            UserERP newUser = new UserERP
            {
                Email      = login.Email,
                UserName   = login.UserName,
                EmployeeId = 1
            };

            IdentityResult createResult = _uow.UserManager.Create(newUser, login.Password);

            if (!createResult.Succeeded)
            {
                ViewBag.message = "Error in Creating User, \n Please try Aagin later ...";
                ModelState.AddModelError("Error", "Already Existing User ...");
                return(View(login));
            }
            ClaimsIdentity identity = _uow.UserManager.CreateIdentity(newUser, "ApplicationCookie");

            Request.GetOwinContext().Authentication.SignIn(identity);

            return(Redirect(GetRedirectUrl(login.retunURL)));
        }
Exemple #2
0
        public ActionResult Manage()
        {
            ClaimsIdentity claimsIdentity = User.Identity as ClaimsIdentity;

            string  userId = claimsIdentity.GetUserId();
            UserERP user   = _uow.UserManager.FindById(userId);

            return(View(new RegisterViewModel
            {
                UserName = user.UserName,
                Email = user.Email
            }));
        }
Exemple #3
0
        public static UserERP FindByEmailAndPassword(this UserManager <UserERP> userManager, string email, string password)
        {
            if (string.IsNullOrEmpty(email) || string.IsNullOrEmpty(password))
            {
                return(null);
            }

            UserERP user = userManager.FindByEmail(email);

            if (user == null || string.IsNullOrEmpty(user.PasswordHash))
            {
                return(null);
            }

            PasswordVerificationResult pResult = userManager.PasswordHasher.VerifyHashedPassword(user.PasswordHash, password);

            return(pResult == PasswordVerificationResult.Failed ? null : user);
        }
Exemple #4
0
        public ActionResult Login(LoginViewModel login)
        {
            if (!ModelState.IsValid)
            {
                return(View(login));
            }

            UserERP loggedUser = _uow.UserManager.FindByEmailAndPassword(login.Email, login.Password);

            if (loggedUser == null)
            {
                ModelState.AddModelError("Error", "Username or password are incorrect");
                ViewBag.message = "Username or password are incorrect";
                return(View(login));
            }

            ClaimsIdentity identity = _uow.UserManager.CreateIdentity(loggedUser, "ApplicationCookie");

            Request.GetOwinContext().Authentication.SignIn(identity);

            return(Redirect(GetRedirectUrl(login.ReturnUrl)));
        }
Exemple #5
0
        //private IdentityResult CreateUser(LoginViewModel login)
        //{

        //}

        private ClaimsIdentity GetUserIdentity(RegisterViewModel login)
        {
            UserERP user = GetUserERP(login);

            return(_uow.UserManager.CreateIdentity(user, "ApplicationCookie"));
        }