コード例 #1
0
ファイル: AuthUser.cs プロジェクト: takethispie/cowork
        public AuthOutput Execute()
        {
            var userId = loginRepository.Auth(CredentialsInput.Email, CredentialsInput.Password);

            if (userId == -1)
            {
                throw new Exception("account not found");
            }
            var user = userRepository.GetById(userId);

            if (user == null)
            {
                throw new Exception("user not found");
            }
            var sub       = subscriptionRepository.GetOfUser(user.Id);
            var authToken = tokenHandler.EncryptToken(new List <Claim> {
                new Claim("Role", user.Type.ToString()),
                new Claim("Id", user.Id.ToString())
            });

            if (sub != null && sub.FixedContract &&
                sub.LatestRenewal.AddMonths(
                    subscriptionTypeRepository.GetById(sub.TypeId)
                    .FixedContractDurationMonth) < DateTime.Today)
            {
                subscriptionRepository.Delete(sub.Id);
                sub = null;
            }
            return(new AuthOutput {
                user = user, sub = sub, auth_token = authToken
            });
        }