public static void CreateSession(CPSession session, bool isPersistant) { try { //storeSession.Add(session.getID(), session); object key = session.getID(); //WCFCache.WCFCache.Current.Insert(key, session, new TimeSpan(24, 0, 0), true); long PeristSessionSpan = Convert.ToInt32(ConfigurationManager.AppSettings["PeristSessionSpan"].ToString()); long defaultSessionSpan = Convert.ToInt32(ConfigurationManager.AppSettings["defaultSessionSpan"].ToString()); int Hours = 0, Minutes = 0, Seconds = 0; if (isPersistant) { Seconds = Convert.ToInt32(PeristSessionSpan % 60); PeristSessionSpan /= 60; Minutes = Convert.ToInt32(PeristSessionSpan % 60); PeristSessionSpan /= 60; Hours = Convert.ToInt32(PeristSessionSpan); ServerCache.ServerCache.Current.Insert(key, session, new TimeSpan(Hours, Minutes, Seconds), true); } else { Seconds = Convert.ToInt32(defaultSessionSpan % 60); defaultSessionSpan /= 60; Minutes = Convert.ToInt32(defaultSessionSpan % 60); defaultSessionSpan /= 60; Hours = Convert.ToInt32(defaultSessionSpan); ServerCache.ServerCache.Current.Insert(key, session, new TimeSpan(Hours, Minutes, Seconds), true); } } catch (Exception) { } }
public ActionResult unlock() { var _db = new ZestorkContainer(); string userName = Request.Form["username"].ToString(); String password = Request.Form["password"].ToString(); String id = Request.Form["id"].ToString(); if (_db.Users.Any(x => x.Username == userName && x.Password == password)) { Users user = _db.Users.SingleOrDefault(x => x.Username == userName && x.isActive == "true"); if (user != null) { user.Locked = "false"; try { _db.SaveChanges(); try { CPSession retVal = TokenManager.getSessionInfo(id); TokenManager.removeSession(id);// remove session if available. } catch (Exception) { //if session is not available.. leave it. } #region Session CPSession session = new CPSession(); session.addAttribute("userName", userName); bool isPersistent = false; // as of now we have only 1 type of login TokenManager.CreateSession(session, isPersistent); #endregion Response.Redirect("/Account/welcome?guid=" + session.getID() + "&username="******"/#/"); } catch (DbEntityValidationException e) { dbContextException dbContextException = new dbContextException(); dbContextException.logDbContextException(e); throw; } } Users User = _db.Users.SingleOrDefault(x => x.Username == userName); LockedScreenModel userInfo = new LockedScreenModel(); userInfo.firstName = User.FirstName; userInfo.lastName = User.LastName; if (User.ImageUrl == "NA" || User.ImageUrl == null) userInfo.imageUrl = "../../Resource/templates/afterLogin/web/img/demo/user-avatar.jpg"; else userInfo.imageUrl = User.ImageUrl; if (userInfo.imageUrl.Contains("../../")) { userInfo.imageUrl = "../" + userInfo.imageUrl; } userInfo.message = "Enter Your Password to Unlock !!"; userInfo.guid = id; userInfo.userName = User.Username; userInfo.postUrl = "http://" + Request.Url.Authority + "Locked/unlock/" + id; User.Locked = "true"; UserPageSetting pageSetting = _db.UserPageSettings.SingleOrDefault(x => x.Username == userName); if (pageSetting != null) userInfo.PageThemeColor = "theme-" + pageSetting.PageThemeColor; else userInfo.PageThemeColor = ""; userInfo.message = "Inactive Account."; return View("index", userInfo); } else { Users User = _db.Users.SingleOrDefault(x => x.Username == userName); LockedScreenModel userInfo = new LockedScreenModel(); userInfo.firstName = User.FirstName; userInfo.lastName = User.LastName; if (User.ImageUrl == "NA" || User.ImageUrl == null) userInfo.imageUrl = "../../Resource/templates/afterLogin/web/img/demo/user-avatar.jpg"; else userInfo.imageUrl = User.ImageUrl; if (userInfo.imageUrl.Contains("../../")) { userInfo.imageUrl = "../" + userInfo.imageUrl; } userInfo.guid = id; userInfo.userName = User.Username; userInfo.postUrl = "http://" + Request.Url.Authority + "Locked/unlock/" + id; User.Locked = "true"; UserPageSetting pageSetting = _db.UserPageSettings.SingleOrDefault(x => x.Username == userName); if (pageSetting != null) userInfo.PageThemeColor = "theme-" + pageSetting.PageThemeColor; else userInfo.PageThemeColor = ""; userInfo.message = "invalid entry !! try again."; return View("index", userInfo); } }
public ActionResult validateForgetPassword() { var _db = new ZestorkContainer(); String guid = Request.QueryString["guid"]; String username = Request.QueryString["username"]; if (!_db.Users.Any(x => x.Username == username)) { Response.Redirect("/"); } if(_db.ForgetPasswords.Any(x=>x.Username == username && x.guid == guid)) { var removeForgetPasswordData = _db.ForgetPasswords.SingleOrDefault(x => x.Username == username); _db.ForgetPasswords.Remove(removeForgetPasswordData); var UserData = _db.Users.SingleOrDefault(x => x.Username == username); UserData.Password = Guid.NewGuid().ToString(); UserData.Locked = "false"; try { _db.SaveChanges(); } catch (DbEntityValidationException e) { dbContextException dbContextException = new CommonMethods.dbContextException(); dbContextException.logDbContextException(e); } #region Session CPSession session = new CPSession(); session.addAttribute("userName", username); bool isPersistent = false; // as of now we have only 1 type of login TokenManager.CreateSession(session, isPersistent); #endregion Response.Redirect("/Account/welcome?guid=" + session.getID() + "&username="******"/#/"); } else { Response.Redirect("/#/forgetpassword"); } return View("Home","Index"); }
public JsonResult Login(string id) { //ServicePointManager.ServerCertificateValidationCallback = delegate //{ return true; }; String returnUrl = ""; String userType = string.Empty; String referral = Request.QueryString["ref"]; var userData = new LogOnModel(); LoginService LoginService = new LoginService(); if (id == "facebook") { String code = Request.QueryString["code"]; if (code == null) Session["userType"] = Request.QueryString["userType"]; else { userType = Session["userType"].ToString(); Session.Remove("userType"); } userData = LoginService.facebookLogin("http://" + Request.Url.Authority + "/Account/Login/facebook/", code, referral, userType); } else if (id == "web") { String userName = Request.Form["userName"]; String password = Request.Form["password"]; String keepMeSignedIn = Request.Form["keepMeSignedInCheckBox"]; if (keepMeSignedIn != null) keepMeSignedIn = "true"; else keepMeSignedIn = "false"; userData = LoginService.webLogin(userName, password, returnUrl, keepMeSignedIn); } else if (id == "google") { if (Request.QueryString["access_token"] != null) { string access_token = Request.QueryString["access_token"]; } String code = Request.QueryString["code"]; if (code == null) Session["userType"] = Request.QueryString["userType"]; else { userType = Session["userType"].ToString(); Session.Remove("userType"); } userData = LoginService.googleLogin("http://" + Request.Url.Authority + "/Account/Login/google", code, referral,userType); } else if (id == "linkedin") { String AbsoluteUri = Request.Url.AbsoluteUri; string oauth_token = Request.QueryString["oauth_token"]; string oauth_verifier = Request.QueryString["oauth_verifier"]; if (oauth_token != null && oauth_verifier != null) { Session["userType"] = Request.QueryString["userType"]; } else { userType = Session["userType"].ToString(); Session.Remove("userType"); } userData = LoginService.linkedinLogin("http://" + Request.Url.Authority + "/Account/Login/linkedin", AbsoluteUri, oauth_token, oauth_verifier, referral, userType); } else if (id == "twitter") { String AbsoluteUri = Request.Url.AbsoluteUri; string oauth_token = Request.QueryString["oauth_token"]; string oauth_verifier = Request.QueryString["oauth_verifier"]; userData = LoginService.twitterinLogin("http://" + Request.Url.Authority + "/Account/Login/twitter", AbsoluteUri, oauth_token, oauth_verifier); } //check for specific status code if (userData.statusCode != null) { if (userData.statusCode != "200") { Response.Redirect("/#/login/" + userData.statusCode); } else { #region Session CPSession session = new CPSession(); session.addAttribute("userName", userData.User.Username); session.addAttribute("type", AccountControllerMethods.getUserType(userData.User.Username)); bool isPersistent = false; // as of now we have only 1 type of login TokenManager.CreateSession(session, isPersistent); userData.User.guid = session.getID(); #endregion if (userData.User.ImageUrl == "NA") userData.User.ImageUrl = "../../Resource/templates/afterLogin/web/img/demo/user-avatar.jpg"; Response.Redirect("/Account/welcome?guid=" + userData.User.guid + "&username="******"&keepMeSignedIn=" + userData.User.keepMeSignedIn + "&type=" + session.getAttributeValue("type") + "&pass=true/#/"); //return View("Index", "User" , userData); //HttpContext.Response.AppendHeader("Authorization", userData.User.guid); } } return Json(userData, JsonRequestBehavior.AllowGet); }