Example #1
0
        public ActionResult Login(String UserName, String Password, String returnUrl)
        {
            TempUser temp = null;

            //db.TempUsers.Where(c => c.name == logindata.UserName && c.password == logindata.Password).First();

            if (temp == null && WebSecurity.Login(UserName, Password, true))
            {
                if (Roles.GetRolesForUser(UserName).Any())
                {
                    if (!(Roles.GetRolesForUser(UserName)[0].Equals("Administrator") || Roles.GetRolesForUser(UserName)[0].Equals("PhoneUser")))
                    {
                        int    userid    = db.UserProfiles.Where(m => m.UserName.Equals(UserName)).First().UserId;
                        int    stationId = db.StationUsers.Where(c => c.UserId == userid).First().StationId.Value;
                        byte[] logo      = db.stations.Where(c => c.id == stationId).First().logo;
                        Session["Logo"]      = logo;
                        Session["UserId"]    = userid;
                        Session["StationId"] = stationId;
                        return(RedirectToAction("Index", "stations"));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }

                //if (returnUrl != null)
                //{
                //    return RedirectToAction(returnUrl);
                //}
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
            else if (temp != null)
            {
                TempUserController con = new TempUserController();
                return(RedirectToAction("Validate", "TempUser", temp));
            }
            else
            {
                ModelState.AddModelError("", "Sorry invalid username or password");
                return(View());
            }
        }
        public ActionResult Login(Login logindata,String returnUrl)
        {
            TempUser temp = db.TempUsers.Where(c => c.name == logindata.UserName && c.password == logindata.Password).First();

            if (temp==null && WebSecurity.Login(logindata.UserName, logindata.Password, true))
            {
                if (Roles.GetRolesForUser(logindata.UserName).Any())
                {
                    if (!(Roles.GetRolesForUser(logindata.UserName)[0].Equals("Administrator") || Roles.GetRolesForUser(logindata.UserName)[0].Equals("PhoneUser")))
                    {
                        int userid = db.UserProfiles.Where(m => m.UserName.Equals(logindata.UserName)).First().UserId;
                        int stationId = db.StationUsers.Where(c => c.UserId == userid).First().StationId;
                        byte[] logo = db.stations.Where(c => c.id == stationId).First().logo;
                        Session["Logo"] = logo;
                        Session["UserId"] = userid;
                        Session["StationId"] = stationId;
                        return RedirectToAction("Index", "stations");
                    }
                }

                if (returnUrl != null)
                {
                    return RedirectToAction(returnUrl);
                }
                else
                    return RedirectToAction("Index", "Home");
            }
            else if (temp != null)
            {
                TempUserController con = new TempUserController();
                return RedirectToAction("Validate","TempUser",temp);
            }
            else
            {
                ModelState.AddModelError("", "Sorry invalid username or password");
                return View(logindata);
            }
        }