Exemplo n.º 1
0
        public async Task <IActionResult> GenerateNew(string rowKey)
        {
            if (HttpContext.IsAdmin())
            {
                var userData = await _userRepository.GetUserByRowKey(rowKey);

                await _filesHelper.GenerateCertAsync(userData, UserInfo.UserName, UserInfo.Ip);
            }
            var users = await GetAllUsers();

            return(new JsonResult(new { Json = JsonConvert.SerializeObject(users) }));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> Authenticate(string googleSignInIdToken, string returnUrl)
        {
            try
            {
                var webSignature = await GoogleJsonWebSignatureEx.ValidateAsync(googleSignInIdToken);

                if (!webSignature.Audience.Equals(ApiClientId) ||
                    string.IsNullOrWhiteSpace(webSignature.Email) ||
                    !Regex.IsMatch(webSignature.Email, AvailableEmailsRegex) || !webSignature.IsEmailValidated)
                {
                    return(Content(string.Empty));
                }

                var user = await _userRepository.GetUserByUserEmail(webSignature.Email);

                if (user == null)
                {
                    user = new UserEntity()
                    {
                        Email = webSignature.Email, Admin = false, Visible = true
                    };
                    await _userRepository.SaveUser(user);
                }

                if (!user.HasCert.HasValue || !(bool)user.HasCert)
                {
                    await _filesHelper.GenerateCertAsync(user, UserInfo.UserName, UserInfo.Ip);
                }

                var claims = new List <Claim>
                {
                    new Claim(ClaimTypes.Sid, webSignature.Email),
                    new Claim("Admin", user.Admin.ToString()),
                    new Claim(ClaimTypes.Name, webSignature.Email.Trim())
                };

                var claimsIdentity  = new ClaimsIdentity(claims, "password");
                var claimsPrinciple = new ClaimsPrincipal(claimsIdentity);
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, claimsPrinciple);

                //await _userHistoryRepository.SaveUserLoginHistoryAsync(user, UserInfo.Ip);
                return(Content(Url.IsLocalUrl(returnUrl) ? returnUrl : HomeUrl));
            }
            catch (Exception ex)
            {
                return(Content(ex.ToString()));
            }
        }