Beispiel #1
0
        public ActionResult Login(Account account)
        {
            if(!ModelState.IsValid)
            {
                return View(account);
            }

            var result = accountService.Login(account);
            if(!result.State){
                ViewBag.Message = result.Message;
                return View(account);
            }

            eRole role = (eRole)result.RetVal;
                       
            string controll = "Home";
            switch (role)
            {
                case eRole.Parent:
                    controll = eRole.Parent.ToString();
                    break;
                case eRole.Investor:
                    controll = eRole.Investor.ToString();
                    break;
                case eRole.School:
                    controll = eRole.School.ToString();
                    break;
            }

            return RedirectToAction("Index",controll);
        }
Beispiel #2
0
        public Result Login(Account account)
        {
            Result res = new Result();
            try
            {
                var user = db.Accounts.Where(x => x.Email == account.Email && x.Password == account.Password).FirstOrDefault();
                if (user == null)
                    return res.Fail("This Account invalid");

                FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.Email, DateTime.Now, DateTime.Now.AddDays(15), true, user.Role.ToString());
                string encTicket = FormsAuthentication.Encrypt(ticket);

                HttpCookie cookie = new HttpCookie(FormsAuthentication.FormsCookieName, encTicket);
                cookie.HttpOnly = true;
                HttpContext.Current.Response.Cookies.Add(cookie);
                return res.Success(user.Role);

            }
            catch (Exception ex)
            {
                return res.Fail(ex.Message);
            }
        }