コード例 #1
0
ファイル: SetUser.cs プロジェクト: half-ogre/qed
        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) });
        }
コード例 #2
0
ファイル: CreateUser.cs プロジェクト: half-ogre/qed
        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;
            }
        }