public ActionResult Login(LoginViewModel model) { IPLUser user = userDB.authenticateUser(model.Username, model.Password); if (user != null) { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, // ticket version model.Username, // authenticated username DateTime.Now, // issueDate DateTime.Now.AddMinutes(30), // expiryDate true, // true to persist across browser sessions user.roleId.ToString() + ":" + user.userId, // can be used to store additional user data FormsAuthentication.FormsCookiePath); // the path for the cookie // Encrypt the ticket using the machine key string encryptedTicket = FormsAuthentication.Encrypt(ticket); // Add the cookie to the request to save it HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (user.roleId == Convert.ToInt32(Constant.userId)) { return(RedirectToAction("Index", "IPLFun")); } return(RedirectToAction("Index", "Home")); } else { return(RedirectToAction("Login", "Account")); } }
public IPLUser authenticateUser(string userName, string password) { IPLUser user = null; using (SqlConnection connection = new SqlConnection(connectionString)) { SqlDataReader reader; try { connection.Open(); SqlCommand command = new SqlCommand("USP_AuthenticateUser", connection); command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@UserName", userName)); command.Parameters.Add(new SqlParameter("@Password", password)); reader = command.ExecuteReader(); while (reader.Read()) { user = new IPLUser(); user.roleId = Convert.ToInt32(reader["roleId"].ToString()); user.userId = Convert.ToInt32(reader["ID"].ToString()); user.Name = reader["Name"].ToString(); } } catch (Exception ex) { } } return(user); }
public ActionResult Bid() { if (getUser() != null) { IPLUser user = getUser(); ViewBag.user = user; List <BidQuestion> bidQuestions = new List <BidQuestion>(); bidQuestions = iplSchedule.getBidQuestionForBidder(user.userId); return(View(bidQuestions)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult History() { if (getUser() != null) { bool isBidActive = false; IPLUser user = getUser(); ViewBag.user = user; List <BidHistory> history = new List <BidHistory>(); history = iplSchedule.getBidderHistory(user.userId, out isBidActive, 0); return(View(history)); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult LoadBidHistory(int MasterId) { if (getUser() != null) { bool isBidActive = false; IPLUser user = getUser(); ViewBag.user = user; List <BidHistory> history = new List <BidHistory>(); history = iplSchedule.getBidderHistory(user.userId, out isBidActive, MasterId); ViewBag.isBidActive = isBidActive; return(PartialView("_BidHistoryPartial", history)); } else { return(RedirectToAction("Index", "Home")); } }
private IPLUser getUser() { HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName]; string username = string.Empty; IPLUser user = null; if (authCookie != null) { user = new IPLUser(); FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(authCookie.Value); string name = ticket.Name; string userData = ticket.UserData; user.userId = Convert.ToInt32(userData.Split(':')[1]); user.Name = Convert.ToString(userData.Split(':')[2]); } return(user); }
public JsonResult getUserPoints() { IPLUser currentUser = getUser(); if (currentUser != null) { DBUser dbuser = new DBUser(); var points = dbuser.getUserBalance(currentUser.userId); return(Json(new { data = new Result { Status = ResultStatus.Success, Message = "Points retrived successfully." }, points = points }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { data = new Result { Status = ResultStatus.Error, Message = "User object is null" } }, JsonRequestBehavior.AllowGet)); } }
public ActionResult Login(LoginViewModel model) { IPLUser user = userDB.authenticateUser(model.Username, model.Password); if (user != null) { FormsAuthenticationTicket ticket = new FormsAuthenticationTicket( 1, // ticket version model.Username, // authenticated username DateTime.Now, // issueDate DateTime.Now.AddMonths(2), // expiryDate true, // true to persist across browser sessions user.roleId.ToString() + ":" + user.userId + ":" + user.Name, // can be used to store additional user data FormsAuthentication.FormsCookiePath); // the path for the cookie // Encrypt the ticket using the machine key string encryptedTicket = FormsAuthentication.Encrypt(ticket); // Add the cookie to the request to save it HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket); cookie.HttpOnly = true; Response.Cookies.Add(cookie); if (user.roleId == 3) { return(Json(new { data = new Result { Status = ResultStatus.Success, Message = "Successfully authenticated." } }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { data = new Result { Status = ResultStatus.Error, Message = "Username or password is incorrect." } }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { data = new Result { Status = ResultStatus.Error, Message = "Username or password is incorrect." } }, JsonRequestBehavior.AllowGet)); } }