Exemplo n.º 1
0
        public override string[] GetRolesForUser(string email)
        {
            if (!HttpContext.Current.User.Identity.IsAuthenticated)
            {
                return(null);
            }

            //check cache
            var cacheKey = string.Format("{0}_role", email);

            if (HttpRuntime.Cache[cacheKey] != null)
            {
                return((string[])HttpRuntime.Cache[cacheKey]);
            }
            string[] roles = new string[] { };
            using (GAPv3Context dc = new GAPv3Context())
            {
                roles = (from a in dc.Roles
                         join b in dc.UserRoles on a.RoleId equals b.RoleId
                         join c in dc.Users on b.UserId equals c.UserId
                         where c.Email.Equals(email)
                         select a.RoleName).ToArray <string>();
                if (roles.Count() > 0)
                {
                    HttpRuntime.Cache.Insert(cacheKey, roles, null, DateTime.Now.AddMinutes(_cacheTimeoutInMinute), Cache.NoSlidingExpiration);
                }
            }
            return(roles);
        }
Exemplo n.º 2
0
 public override bool ValidateUser(string email, string password)
 {
     using (GAPv3Context dc = new GAPv3Context())
     {
         var user = dc.Users.Where(a => a.Email.Equals(email) && a.Password.Equals(password)).FirstOrDefault();
         if (user != null)
         {
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 3
0
        public ActionResult Login(User UserInput, string ReturnUrl = "")
        {
            //using (GAPv2Context dc = new GAPv2Context())
            //{
            //    var user = dc.User.Where(a => a.Email.Equals(UserInput.Email) &&
            //                                  a.Password.Equals(UserInput.Password)).FirstOrDefault();
            //    if (user != null)
            //    {
            //        FormsAuthentication.SetAuthCookie(user.Email, true);
            //        if (Url.IsLocalUrl(ReturnUrl))
            //        {
            //            return Redirect(ReturnUrl);
            //        }
            //        else
            //        {
            //            return RedirectToAction("Index", "Home");
            //        }
            //    }
            //}
            //ModelState.Remove("Password");
            //return View();
            //if (ModelState.IsValid)
            //{
            //    var isValidUser = Membership.ValidateUser(UserInput.Email, UserInput.Password);
            //    if (isValidUser)
            //    {
            //        FormsAuthentication.SetAuthCookie(UserInput.Email,true);
            //        if (Url.IsLocalUrl(ReturnUrl))
            //        {
            //            return Redirect(ReturnUrl);
            //        }
            //        else
            //        {
            //            return RedirectToAction("Index", "Home");
            //        }
            //    }
            //}


            if (ModelState.IsValid)
            {
                bool isValidUser = Membership.ValidateUser(UserInput.Email, UserInput.Password);
                if (isValidUser)
                {
                    User user = null;
                    using (GAPv3Context dc = new GAPv3Context())
                    {
                        user = dc.Users.Where(a => a.Email.Equals(UserInput.Email)).FirstOrDefault();
                    }

                    if (user != null)
                    {
                        JavaScriptSerializer js          = new JavaScriptSerializer();
                        string data                      = js.Serialize(user);
                        FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(1, user.Email, DateTime.Now,
                                                                                         DateTime.Now.AddMinutes(30), true, data);
                        string     encToken     = FormsAuthentication.Encrypt(ticket);
                        HttpCookie authoCookies = new HttpCookie(FormsAuthentication.FormsCookieName, encToken);
                        Response.Cookies.Add(authoCookies);
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }


            ModelState.Remove("Password");
            return(View());
        }
Exemplo n.º 4
0
 public ReportService(GAPv3Context context)
 {
     _context = context;
 }
Exemplo n.º 5
0
 public OrganisationService(GAPv3Context context)
 {
     _context = context;
 }
Exemplo n.º 6
0
 public OrganisationsController()
 {
     _context = new GAPv3Context();
     _service = new OrganisationService(_context);
 }
Exemplo n.º 7
0
 public ReportsController()
 {
     _context = new GAPv3Context();
     _service = new ReportService(_context);
 }