Ejemplo n.º 1
0
        public static void SetUser(
            this IDictionary<string, object> environment,
            User user)
        {
            var owinContext = new OwinContext(environment);

            var identity = new GenericIdentity(user.Username, "Session");

            owinContext.Authentication.SignIn(new[] { new ClaimsIdentity(identity) });
        }
Ejemplo n.º 2
0
        public static User CreateUser(
            string username,
            string password,
            string emailAddress)
        {
            if (String.IsNullOrEmpty(username)) throw new ArgumentException("Username must not be null or empty.", "username");
            if (String.IsNullOrEmpty(password)) throw new ArgumentException("Password must not be null or empty.", "password");

            using (var ravenSession = OpenRavenSession())
            {
                var user = new User
                {
                    Username = username,
                    PasswordHash = GeneratePasswordHash(password),
                    EmailAddress = emailAddress
                };

                ravenSession.Store(user);
                ravenSession.SaveChanges();

                return user;
            }
        }