コード例 #1
0
        public async Task <string> Login(string userName, string password)
        {
            if (string.IsNullOrEmpty(userName) || string.IsNullOrEmpty(password))
            {
                return(null);
            }

            var soldier = await _soldierRepository.GetByEmail(userName);

            if (soldier != null)
            {
                return(!_jwtHandler.VerifyPasswordHash(password, soldier.PasswordHash, soldier.PasswordSalt)
                    ? null
                    : _jwtHandler.CreateToken(soldier));
            }
            var commander = await _commanderRepository.GetByEmail(userName);

            if (commander != null)
            {
                return(!_jwtHandler.VerifyPasswordHash(password, commander.PasswordHash, commander.PasswordSalt)
                    ? null
                    : _jwtHandler.CreateToken(commander));
            }
            var admin = await _adminRepository.GetByEmail(userName);

            if (admin != null)
            {
                return(!_jwtHandler.VerifyPasswordHash(password, admin.PasswordHash, admin.PasswordSalt)
                    ? null
                    : _jwtHandler.CreateToken(admin));
            }
            return(null);
        }