Esempio n. 1
0
 //Check User Cridentils is vallid or not
 public DataTable CheckLoginCridentials(AccountModel account)
 {
     AddParameter("@username", account.UserName);
     AddParameter("@password", account.Password);
     AddParameter("@ipaddress", Utilities.GetIP());
     return this.GetDataTable("[usp_CheckLoginCridentials]");
 }
Esempio n. 2
0
        public ActionResult LogOff()
        {
            AccountModel account = new AccountModel();
            HttpCookie useCookie = HttpContext.Request.Cookies["myCookie"];
            account.UserName = useCookie.Values["UserName"];
            accountDAL = new AccountDAL();
            if (String.Compare(accountDAL.LogOff(account).ToString(), "SUCCESS") == 0)
            {
                Session.RemoveAll();
                Response.Cookies.Clear();
                useCookie.Expires = DateTime.Now.AddDays(-1d);
                Response.Cookies.Add(useCookie);

                FormsAuthentication.SignOut();
            }
            Session["LogOut"] = true;
            return RedirectToAction("LogOn", "Account");
        }
Esempio n. 3
0
        public ActionResult LogOn()
        {
            var logOn = new AccountModel();
            var valid = TryUpdateModel(logOn);

            if (valid)
            {
                accountModel = new AccountModel();
                accountModel.UserName = logOn.UserName;
                accountModel.Password = logOn.Password;
                //accountModel.RememberMe = logon.RememberMe;

                accountDAL = new AccountDAL();
                DataTable userdetails = accountDAL.CheckLoginCridentials(accountModel);

                if (userdetails.Rows.Count > 0)
                {
                    String LoginStatus;

                    if (!String.IsNullOrEmpty(userdetails.Rows[0]["LoginStatus"].ToString()) == true)
                    {
                        LoginStatus = userdetails.Rows[0]["LoginStatus"].ToString();

                        if (LoginStatus == "A")
                        {
                            if (!String.IsNullOrEmpty(userdetails.Rows[0]["RoleID"].ToString()))
                            {
                                String roleid = userdetails.Rows[0]["RoleID"].ToString();
                                FormsAuthentication.SetAuthCookie(logOn.UserName, false);
                                //FormsAuthenticationTicket FrmAutTicket = new FormsAuthenticationTicket(1, model.UserName, DateTime.Now, DateTime.Now.AddMinutes(3600), false, roleid);
                                //HttpCookie Cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(FrmAutTicket));
                                //Response.Cookies.Add(Cookie);

                                HttpCookie myCookie = new HttpCookie("myCookie");

                                myCookie.Values.Add("UserName", logOn.UserName);
                                myCookie.Values.Add("FirstName", userdetails.Rows[0]["FirstName"].ToString());
                                myCookie.Values.Add("RoleID", roleid);
                                myCookie.Values.Add("CommunityID", userdetails.Rows[0]["CommunityID"].ToString());
                                myCookie.Values.Add("CommunityName", userdetails.Rows[0]["CommunityName"].ToString());
                                myCookie.Values.Add("UserID", userdetails.Rows[0]["UserID"].ToString());
                                myCookie.Values.Add("CommunityMenuOptions", userdetails.Rows[0]["CommunityMenuOptions"].ToString());

                                myCookie.HttpOnly = true;
                                Response.Cookies.Add(myCookie);

                                String RedirectURL = null;
                                switch (roleid)
                                {
                                    case "1": RedirectURL = "SuperAdministrator";
                                        break;
                                    case "2": RedirectURL = "Administrator";
                                        break;
                                    case "3": RedirectURL = "SecurityManager"; break;
                                    case "4": RedirectURL = "SecurityPersonnel"; break;
                                    case "5": RedirectURL = "HomeOwner"; break;
                                    case "6": RedirectURL = "ServiceProvider"; break;
                                }
                                return Json(new { result = true, redirecturl = RedirectURL });
                            }
                        }
                        else if (LoginStatus == "P")
                        {
                            ModelState.AddModelError("P1", "You already login from some other ipaddress." + '\n' + "Wait for " + userdetails.Rows[0]["MinutesToWait"].ToString() + " minutes");
                            String[] lostLoginDetails = userdetails.Rows[0]["LastLogin"].ToString().Split(' ');
                            ModelState.AddModelError("P2", "Your last login on " + lostLoginDetails[0] + " @ " + lostLoginDetails[1]);
                        }
                        else if (LoginStatus == "FP")
                        {
                            ModelState.AddModelError("FP", "Requested for Password Change, Link has been sent to your email.");
                        }
                        else if (LoginStatus == "MM")
                        {
                            ModelState.AddModelError("MM", "Username, Password mismatch");
                        }
                        else if (LoginStatus == "NF")
                        {
                            ModelState.AddModelError("NF", "The username is not registered.");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("problem", "Problem with website, Please Try after some time.");
                    }
                }
                else
                {
                    ModelState.AddModelError("NR", "User not registered yet.");
                }
            }
            else
            {
                ModelState.AddModelError("error", "Model Errors.");
            }
            // return Json(new { result = ModelState.IsValid, errors = GetErrorsFromModelState() });
            return Json(new { result = false, errors = GetErrorsFromModelState(), errorPartial = RenderPartialViewToString("_LogOn", logOn) });
        }
Esempio n. 4
0
 internal DataTable UserNameCheck(AccountModel model)
 {
     AddParameter("@username", model.UserName);
     return this.GetDataTable("[usp_UserNameCheck]");
 }
Esempio n. 5
0
 public object LogOff(AccountModel account)
 {
     AddParameter("@username", account.UserName);
     return this.ExecuteScalar("[usp_LogOff]");
 }
Esempio n. 6
0
 public object ForgotPassword(AccountModel account)
 {
     AddParameter("@username", account.UserName);
     return this.ExecuteScalar("[usp_ForgotPasswordRequest]");
 }