Exemple #1
0
        /// <summary>
        /// Login the user
        /// </summary>
        /// <param name="context">HttpContext object</param>
        /// <param name="username">Username property</param>
        /// <param name="password">Password property</param>
        /// <param name="referrer">Referrer property</param>
        /// <returns>Jessica Response object</returns>
        private Response LoginUser(HttpContext context, string username, string password, string referrer)
        {
            var db = new DBFactory();
              var user = db.DB().User.FindByLoginAndPassword(username, password.ToSHA512());

              if (user != null) {
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(username, false, 15);
            var cookieStr = FormsAuthentication.Encrypt(ticket);
            var cookie = new HttpCookie(FormsAuthentication.FormsCookieName, cookieStr);
            cookie.Path = FormsAuthentication.FormsCookiePath;
            context.Response.Cookies.Add(cookie);

            context.Session.Remove("user.name");
            context.Session.Add("user.name", user.Name);
            context.Session.Remove("user.login");
            context.Session.Add("user.login", user.Login);
            context.Session.Remove("user.id");
            context.Session.Add("user.id", String.Format("{0}", user.Id));

            return Response.AsRedirect(String.Format("{0}?login=true", referrer));
              }
              else {
            return Response.AsRedirect(String.Format("/authentication/login?ref={0}&invalid=true", referrer));
              }
        }
Exemple #2
0
        /// <summary>
        /// GetView method, to return a string value based on the url
        /// </summary>
        /// <param name="url">String object of the url, mostly only the domainname, without http://</param>
        /// <returns>The alias of the view</returns>
        private string GetView(string url)
        {
            DBFactory db = new DBFactory();
              var view = db.DB().View.FindByUrl(url);

              string viewAka = String.Empty;
              if (view == null) {
            viewAka = "default";
              }
              else {
            viewAka = view.Aka;
              }

              return viewAka;
        }