public void LoginUser(string email, string username, bool rememberMe = true)
        {
            var id   = _crypto.GetMd5Hash(email);
            var data = String.Format("{0}|{1}", email, username);

            var authTicket = new FormsAuthenticationTicket(
                10,
                id,
                DateTime.Now,
                DateTime.Now.AddDays(14),
                rememberMe,
                data);

            string encryptedTicket = FormsAuthentication.Encrypt(authTicket);

            if (HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName] != null)
            {
                HttpContext.Current.Response.Cookies.Remove(FormsAuthentication.FormsCookieName);
            }

            var authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);

            authCookie.Expires = DateTime.Now.AddDays(180);
            HttpContext.Current.Response.Cookies.Add(authCookie);

            // HttpContext.Current.Session[BaseController.SessionKeys.UserName] = username;
        }
        public void Handle(CreateUser c)
        {
            var salt = _crypto.GenerateSalt();
            var id   = _crypto.GetMd5Hash(c.Email);

            _repository.Perform(id, user => user.Create(
                                    id,
                                    c.UserName,
                                    _crypto.GetPasswordHash(c.Password, salt),
                                    salt,
                                    c.Email,
                                    c.FacebookId));
        }
Esempio n. 3
0
 public UserView GetByEmail(string email)
 {
     return(GetById(_crypto.GetMd5Hash(email)));
 }