Ejemplo n.º 1
0
        public ActionResult Login(tblAdminAccount model)
        {
            List <tblAdminAccount> objAdminaccountList = db.sp_CheckAdminLogin(model.UserName, Utility.Encript(model.Password, "ER")).ToList();

            if (objAdminaccountList.Count > 0)
            {
                Session["AdminUser"] = objAdminaccountList[0].UserName;
                string   lastAccessDateTime    = objAdminaccountList[0].LastAccessedDateTime.ToString();
                DateTime CurrentAccessDateTime = DateTime.Now;
                if (string.IsNullOrEmpty(lastAccessDateTime))
                {
                    Session["lastAccessDateTime"] = CurrentAccessDateTime.ToString();
                }
                else
                {
                    Session["lastAccessDateTime"] = lastAccessDateTime;
                }
                tblAdminAccount objAdminAccount = db.tblAdminAccounts.Find(objAdminaccountList[0].UserName);
                objAdminAccount.LastAccessedDateTime = CurrentAccessDateTime;

                db.SaveChanges();



                ViewBag.Error = string.Empty;

                return(RedirectToAction("ControlPanel"));
            }
            else
            {
                ViewBag.Error = "Invalid UserName Or Password";
            }

            return(View());
        }
Ejemplo n.º 2
0
        public ActionResult Login(string email, string password)
        {
            // Here i changed the return type of the SP to make it return a model type ("tblAdminAccount" model type)
            List <tblAdminAccount> objAdminAccount = dbEntities.SP_CheckAdminLogin(email, Utility.Encrypt(password, "ER")).ToList();

            if (objAdminAccount.Count > 0)
            {
                //if (dbEntities.SP_CheckUserAccountStatus(email, 1).FirstOrDefault().Value > 0)
                //{
                //    ViewBag.Status = "Please check your mail to activate the account!!!";
                //    ViewBag.Activation = 1;
                //    TempData["Email"] = email;
                //    return View();
                //}
                //if (dbEntities.SP_CheckUserAccountStatus(email, 2).FirstOrDefault().Value > 0)
                //{
                //    ViewBag.Status = "Your Account has been cancelled. Please contact to Administration!!!";
                //    return View();
                //}

                //Session["UserId"] = objAdminAccount[0].UserId;

                //Session["FirstName"] = objAdminAccount[0].tblUserPersonalDetails.FirstOrDefault().FirstName;

                Session["EmailId"] = objAdminAccount[0].Emailid;

                string lastAccessedDateTime = objAdminAccount[0].LastAccessedDateTime.ToString();

                DateTime currentAccessedDateTime = DateTime.Now;

                if (string.IsNullOrEmpty(lastAccessedDateTime))
                {
                    Session["LastAccessedDateTime"] = currentAccessedDateTime.ToString();
                }
                else
                {
                    Session["LastAccessedDateTime"] = lastAccessedDateTime;
                }

                //tblUserAccountDetail objUserAccountDetail = dbEntities.tblUserAccountDetails.Find(objAdminAccount[0].UserId);
                tblAdminAccount tblObjAdminAccount = dbEntities.tblAdminAccounts.Find(objAdminAccount[0].Emailid);
                tblObjAdminAccount.LastAccessedDateTime = currentAccessedDateTime;

                dbEntities.SaveChanges();
                ////////////
                //string s = Session["ToPage"].ToString();
                //if (Session["ToPage"] == "MyReminders")

                //    return RedirectToAction(s, "Home", new { area = "User" });
                ///////////////

                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.Status = "Invalid Email Address or Password";
            }
            return(View());
        }
Ejemplo n.º 3
0
        public ActionResult ChangePassword(Models.Admin model)
        {
            if (Session["AdminUser"] == null)
            {
                return(RedirectToAction("Login"));
            }

            tblAdminAccount objAdminAccount = dbEntities.tblAdminAccounts.Find(Session["AdminUser"].ToString());

            objAdminAccount.Password = Utility.Encrypt(model.NewPassword, "ER");

            if (dbEntities.SaveChanges() > 0)
            {
                ViewBag.Status = 1;
            }
            else
            {
                ViewBag.Status = 0;
            }

            return(View());
        }
Ejemplo n.º 4
0
        public ActionResult ChangePassword(Models.Admin model)
        {
            if (Session["AdminUser"] == null)
            {
                return(RedirectToAction("Login"));
            }
            if (ModelState.IsValid)
            {
                tblAdminAccount objAdminAccount = db.tblAdminAccounts.Find(Session["AdminUser"].ToString());
                objAdminAccount.Password = Utility.Encript(model.NewPassword, "ER");

                if (db.SaveChanges() > 0)
                {
                    ViewBag.Status = "Password Sucessfully Changed";
                }
                else
                {
                    ViewBag.Status = "Password changed failed";
                }
            }
            return(View());
        }
Ejemplo n.º 5
0
        public ActionResult ChangePassword(string oldPassword, string newPassword, string newPasswordAgain)
        {
            if (Session["EmailId"] == null)
            {
                return(RedirectToAction("Login"));
            }

            tblAdminAccount objAdminAccount = dbEntities.tblAdminAccounts.Find(Session["EmailId"].ToString());

            objAdminAccount.password = Utility.Encrypt(newPassword, "ER");

            if (dbEntities.SaveChanges() > 0)
            {
                ViewBag.Status = 1;
            }
            else
            {
                ViewBag.Status = 0;
            }

            return(View());
        }
Ejemplo n.º 6
0
        public ActionResult Login(tblAdminAccount model)                                                                                                //parsing the model which hold validated UserName and Password was Entered by user to compare with the ones in the database
        {
            List <tblAdminAccount> objAdminAccountList = dbEntities.SP_CheckAdminLogin(model.UserName, Utility.Encrypt(model.Password, "ER")).ToList(); // declaring a list table object and using Entities and stored procedur compare (model.UserName, model.Password after encrypt it)(the user inputed values) with the ones in the database using the stored procedur to search about mathcing in the database as we parse for it these two values

            if (objAdminAccountList.Count > 0)                                                                                                          //if there is value in the first index from the list that means we find matching from database
            {
                Session["AdminUser"] = objAdminAccountList[0].UserName;                                                                                 // saving the admin name in session to use it in the pages where needed

                string lastAccessedDateTime = objAdminAccountList[0].LastAccessedDateTime.ToString();

                DateTime currentAccessedDateTime = DateTime.Now;

                if (string.IsNullOrEmpty(lastAccessedDateTime))//new user first time
                {
                    Session["LastAccessedDateTime"] = currentAccessedDateTime.ToString();
                }
                else //old user we have value for last date time in database
                {
                    Session["LastAccessedDateTime"] = lastAccessedDateTime;
                }

                // for updating last access login
                tblAdminAccount objAdminAccount = dbEntities.tblAdminAccounts.Find(objAdminAccountList[0].UserName);
                objAdminAccount.LastAccessedDateTime = currentAccessedDateTime;

                dbEntities.SaveChanges();

                ViewBag.Error = string.Empty;
                return(RedirectToAction("ControlPanel"));
            }
            else // no username and password matching found in database
            {
                ViewBag.Error = "Invalid User Name or Password";
            }
            return(View());
        }