Beispiel #1
0
 // GET: Account
 public ActionResult Index()
 {
     using (QuestionsDBContext db = new QuestionsDBContext())
     {
         return(View(db.userAccount.ToList()));
     }
 }
Beispiel #2
0
 public ActionResult Register(UserAccount account)
 {
     if (ModelState.IsValid)
     {
         using (QuestionsDBContext db = new QuestionsDBContext())
         {
             db.userAccount.Add(account);
             db.SaveChanges();
         }
         ModelState.Clear();
         ViewBag.Message = account.FirstName + " " + account.LastName + " successfully registered";
     }
     return(View());
 }
Beispiel #3
0
        public ActionResult Login(UserAccount user, [Bind(Include = "ID,NameOfSession")] SessionSave Sessions)
        {
            using (QuestionsDBContext db = new QuestionsDBContext())
            {
                var usr = db.userAccount.Single(u => u.UserName == user.UserName && u.Password == user.Password);
                Session["UserID"]   = usr.UserID.ToString();
                Session["Username"] = usr.UserName.ToString();
                if (user != null)
                {
                    //authorization code starts here
                    bool userAutherised = true;
                    if (userAutherised)
                    {
                        //create the authentication ticket
                        var    serializer = new JavaScriptSerializer();
                        string userData   = serializer.Serialize(usr.UserName.ToString());

                        var authTicket = new FormsAuthenticationTicket(
                            1,
                            usr.UserName.ToString(),     //user id
                            DateTime.Now,
                            DateTime.Now.AddMinutes(20), // expiry
                            true,                        //true to remember
                            userData,                    //roles
                            FormsAuthentication.FormsCookiePath
                            );
                        HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(authTicket));
                        Response.Cookies.Add(cookie);

                        HttpCookie chkUsername = new HttpCookie("Username");
                        chkUsername.Expires = DateTime.Now.AddSeconds(3600);
                        chkUsername.Value   = Session["Username"].ToString();
                        Request.Cookies.Add(chkUsername);
                    }

                    //authorization code ends here



                    return(RedirectToAction("Index"));
                }
                else
                {
                    ModelState.AddModelError("", "Username or Password is wrong");
                }
            }
            return(View());
        }
Beispiel #4
0
 public ActionResult Login(UserAccount user)
 {
     using (QuestionsDBContext db = new QuestionsDBContext())
     {
         var usr = db.userAccount.Single(u => u.UserName == user.UserName && u.Password == user.Password);
         if (user != null)
         {
             Session["UserID"]   = usr.UserID.ToString();
             Session["Username"] = usr.UserName.ToString();
             return(RedirectToAction("LoggedIn"));
         }
         else
         {
             ModelState.AddModelError("", "Username or Password is wrong");
         }
     }
     return(View());
 }