public void SetUserId(Guid userId, bool rememberMe) { try { HttpCookie signinCookie = new HttpCookie("Condour"); signinCookie.Value = userId.ToString(); if (rememberMe) { signinCookie.Expires = DateTime.Now.AddDays(5); } else { signinCookie.Expires = DateTime.Now.AddDays(2); } UserDBOperations db = new UserDBOperations(); UserInfo user = db.GetUser(userId); if (user != null) { FormsAuthentication.SetAuthCookie(user.UserName, true); } this.ControllerContext.HttpContext.Response.Cookies.Add(signinCookie); } catch (Exception ex) { Library.WriteLog("At setuserid saving userid to cookie", ex); } }
public override string[] GetRolesForUser(string username) { string[] roleColl = new string[1]; try { UserDBOperations db = new UserDBOperations(); roleColl = db.GetRoelsForUser(username); } catch (Exception ex) { Library.WriteLog("At get roles role provider", ex); return(new string[] { }); } return(roleColl); }
public override bool IsUserInRole(string username, string roleName) { bool isUserInRole = false; try { UserDBOperations db = new UserDBOperations(); isUserInRole = db.IsUserInRole(username, roleName); } catch (Exception ex) { Library.WriteLog("At IsUserInRole role provider", ex); return(false); } return(isUserInRole); }
public ActionResult Login(FormCollection coll, string ReturnUrl = null) { try { UserDBOperations db = new UserDBOperations(); Guid userId = db.IsValidUser(coll["userName"], coll["pwd"]); if (userId != Guid.Empty)//valid user { SetUserId(userId, false); if (Url.IsLocalUrl(ReturnUrl)) { return(Redirect(ReturnUrl)); } else { if (coll["userName"].ToLower() == "admin" && coll["pwd"].ToLower() == "admin") { return(RedirectToAction("GetUsers", "Admin")); } else { return(RedirectToAction("UserDetails", "Home", new { userName = coll["userName"] })); } } } else { @ViewBag.status = " Invalid Email/Phone Number or Password"; } } catch (Exception ex) { Library.WriteLog("At Login UserName - " + coll["email-phone"], ex); } return(View()); }