コード例 #1
0
        public Token Authorize(string userName, string userPassword)
        {
            using (var context = new ZyronatorDataContext(_configurationProperties.ConnectionString))
            {
                ApplicationUser appUser = context.ApplicationUsers.SingleOrDefault(us => us.UserName == userName);

                if (appUser == null)
                {
                    return(null);
                }

                bool verified = Crypto.VerifyHashedPassword(appUser.UserPassword, userPassword);

                if (!verified)
                {
                    return(null);
                }

                appUser.AuthorizationToken = Guid.NewGuid();
                appUser.AuthorizationDate  = _configurationProperties.CurrentDate.Date;
                context.SaveChanges();

                return(new Token(appUser.AuthorizationToken, appUser.AuthorizationDate));
            }
        }
コード例 #2
0
        public Token Authorize(Guid token)
        {
            using (var context = new ZyronatorDataContext(_configurationProperties.ConnectionString))
            {
                ApplicationUser appUser = context.ApplicationUsers.SingleOrDefault(us => us.AuthorizationToken == token);

                if (appUser == null)
                {
                    return(null);
                }

                appUser.AuthorizationToken = Guid.NewGuid();
                appUser.AuthorizationDate  = _configurationProperties.CurrentDate.Date;
                context.SaveChanges();

                return(new Token(appUser.AuthorizationToken, appUser.AuthorizationDate));
            }
        }
コード例 #3
0
        public ZyronatorUser AddUser(NewZyronatorUser user)
        {
            ApplicationUser newUser = new ApplicationUser();

            newUser.UserName     = user.UserName;
            newUser.UserPassword = Crypto.HashPassword(user.Password);

            int newId = 0;

            using (var context = new ZyronatorDataContext(_configurationProperties.ConnectionString))
            {
                context.Database.Log = Console.WriteLine;
                context.ApplicationUsers.Add(newUser);
                context.SaveChanges();

                newId = newUser.UserId;
            }

            return(new ZyronatorUser(newId, newUser.UserName));
        }