public ActionResult ChangePassword(ChangePasswordViewModel model)
        {
            if (model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("", "password and Confirm password doesnot match");
                return(View(model));
            }

            UserMaster user = UserMaster.GetUserById(Convert.ToInt32(Session["uid"]), con);

            if (user == null)
            {
                ModelState.AddModelError("", "Invalid User or Session");
                return(View(model));
            }

            if (user.hashed_password != UserMaster.EncryptString(model.Password))
            {
                ModelState.AddModelError("", "Invalid Old Password");
                return(View(model));
            }
            UserMaster.UpdatePassword(user.email, model.Password, con);
            //Write Code to send password change email
            return(RedirectToAction("Success", "Account", new { msg = "You have changed you password Successfully." }));
        }
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            //var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);

            UserMaster user = UserMaster.Login(model.Email, model.Password, con);

            string strp = UserMaster.EncryptString(model.Password);

            //UserLoginInfo user1 = new UserMaster();

            if (user == null)
            {
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }
            switch (user.user_status)
            {
            case UserStatus.Disabled:
                return(RedirectToLocal(returnUrl + "&Disabled"));

            case UserStatus.Suspended:
                return(RedirectToLocal(returnUrl + "&Suspended"));

            case UserStatus.LoggedIn:
                return(RedirectToLocal(returnUrl + "&LoggedIn"));

            //return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case UserStatus.Active:
            {
                if (strp == user.hashed_password)
                {
                    Session["uid"]         = user.uid;
                    Session["DisplayName"] = user.display_name;
                    Session["cid"]         = user.cid;
                    return(RedirectToAction("Dashboard", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return(View(model));
                }
            }

            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }

            return(View(model));
        }
        public ActionResult CreateUser(CreateUserViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            if (model.Password != model.ConfirmPassword)
            {
                ModelState.AddModelError("", "password and Confirm password doesnot match");
                return(View(model));
            }

            UserMaster user = UserMaster.GetUserByEmail(model.EmailAddress, con);

            if (user != null)
            {
                ModelState.AddModelError("", "Email already Registered");
                return(View(model));
            }

            string strp = UserMaster.EncryptString(model.Password);

            UserMaster new_user = new UserMaster();

            new_user.cid             = Convert.ToInt32(Session["cid"]);
            new_user.email           = model.EmailAddress;
            new_user.display_name    = model.DisplayName;
            new_user.hashed_password = strp;
            new_user.mobile_number   = model.Mobile;
            new_user.created_by_uid  = Convert.ToInt32(Session["uid"]);

            int i = UserMaster.CreateUser(new_user, con);

            if (i > 0)
            {
                user = UserMaster.GetUserByEmail(model.EmailAddress, con);
                CommonStuff.SendEmail(user.email, "Welcome to DotNetIsEasy.com", CommonStuff.getEmailVerificationBody(user.email, user.emailvalidationToken));

                //user = UserMaster.Login(model.EmailAddress, model.Password, con);

                //Session["uid"] = user.uid;
                //Session["DisplayName"] = user.display_name;
                //Session["cid"] = user.cid;
                return(RedirectToAction("Success", "Account"));
            }
            else
            {
                return(View(model));
            }
        }
        public ActionResult CreateUser(CreateUserViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            UserMaster user = UserMaster.GetUserByEmail(model.EmailAddress, con);

            if (user != null)
            {
                ModelState.AddModelError("", "Email already Registered");
                return(View(model));
            }

            string strp = UserMaster.EncryptString(model.Password);

            UserMaster new_user = new UserMaster();

            new_user.cid             = Convert.ToInt32(Session["cid"]);
            new_user.email           = model.EmailAddress;
            new_user.display_name    = model.DisplayName;
            new_user.hashed_password = strp;
            new_user.mobile_number   = model.Mobile;
            new_user.created_by_uid  = Convert.ToInt32(Session["uid"]);

            int i = UserMaster.CreateUser(new_user);

            if (i > 0)
            {
                return(RedirectToAction("Dashboard", "Home"));
            }
            else
            {
                return(View(model));
            }
        }
        public ActionResult Login(LoginViewModel model, string returnUrl)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            Logger.log.Info("Login: emailId=" + model.Email + ",IP=" + CommonStuff.GetLocalIPAddress());
            // This doesn't count login failures towards account lockout
            // To enable password failures to trigger account lockout, change to shouldLockout: true
            //var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false);

            UserMaster user = UserMaster.Login(model.Email, model.Password, con);

            string strp = UserMaster.EncryptString(model.Password);

            //UserLoginInfo user1 = new UserMaster();

            if (user == null)
            {
                ModelState.AddModelError("", "Invalid login attempt.");
                ViewBag.ReturnUrl = returnUrl;
                return(View(model));
            }

            if (user.emailvalidation == 0)
            {
                ModelState.AddModelError("ValidateEmail", "Please Validate your Email First");
                ViewBag.ReturnUrl = returnUrl;
                return(View(model));
            }

            switch (user.user_status)
            {
            case UserStatus.Disabled:
                return(RedirectToLocal(returnUrl + "&Disabled"));

            case UserStatus.Suspended:
                return(RedirectToLocal(returnUrl + "&Suspended"));

            case UserStatus.LoggedIn:
                return(RedirectToLocal(returnUrl + "&LoggedIn"));

            //return RedirectToAction("SendCode", new { ReturnUrl = returnUrl, RememberMe = model.RememberMe });
            case UserStatus.Active:
            {
                if (strp == user.hashed_password)
                {
                    Session["uid"]         = user.uid;
                    Session["DisplayName"] = user.display_name;
                    Session["cid"]         = user.cid;
                    if (string.IsNullOrEmpty(returnUrl))
                    {
                        return(RedirectToAction("PostArtical", "Artical"));
                    }
                    else
                    {
                        return(Redirect(returnUrl));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Invalid login attempt.");
                    return(View(model));
                }
            }

            default:
                ModelState.AddModelError("", "Invalid login attempt.");
                return(View(model));
            }

            return(View(model));
        }