示例#1
0
        public static void DoLogin(CurrentLogedInUser LogedInUserEntity, HttpContextBase HttpContext)
        {
            var timeOut = 60 * 48; //48 hours
            FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, LogedInUserEntity.userid, DateTime.Now, DateTime.Now.AddMinutes(timeOut), false, CommonUtility.Serialize <CurrentLogedInUser>(LogedInUserEntity));
            string     encryptedTicket           = FormsAuthentication.Encrypt(authTicket);
            HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            HttpContext.Response.Cookies.Add(authCookie);
        }
示例#2
0
        public ActionResult Login(CurrentLogedInUser model, string returnUrl)
        {
            var header = new System.Collections.Specialized.NameValueCollection
            {
                { "IsAdmin", "true" }
            };

            using (var objApiClient = new RestAPIClient
            {
                requestUriString = CommonUtility.GetAppSettingKey("RestServiceURL") + "security/obtainAuthToken",
                contentType = "application/x-www-form-urlencoded",
                headerNameValueCollection = header,
                postDataString = CommonUtility.Serialize <CurrentLogedInUser>(model)
            })
            {
                var apiResponse = objApiClient.Post();
                if (!apiResponse.type.Contains("error") && apiResponse.body != null && apiResponse.code != -3)
                {
                    CommonUtility.DoLogin(CommonUtility.Deserialize <CurrentLogedInUser>(apiResponse.body.ToString()), this.HttpContext);
                }
                else
                {
                    ViewBag.Title = "Login";
                    ModelState.AddModelError("error_msg", apiResponse.message ?? "Login failed. Please enter valid userid and password");
                    if (apiResponse.code == 1 || apiResponse.code == 2)
                    {
                        ViewBag.Error = apiResponse.message;
                    }
                    else
                    {
                        ViewBag.Error = "Login failed, please try again";
                    }
                    return(View(model));
                }
            }
            ViewBag.Error = "";
            return(RedirectToAction("Index", "Home"));
        }
示例#3
0
 public AuthenticationWebPlatformPrincipal(IIdentity identity, CurrentLogedInUser udata)
 {
     this.Identity = identity;
     this.userData = udata;
 }