Пример #1
0
        public async Task <IActionResult> Authorize(OpenIdConnectRequest request)
        {
            if (!User.Identity.IsAuthenticated)
            {
                // If the client application request promptless authentication,
                // return an error indicating that the user is not logged in.
                if (request.HasPrompt(OpenIdConnectConstants.Prompts.None))
                {
                    var properties = new AuthenticationProperties(new Dictionary <string, string>
                    {
                        [OpenIdConnectConstants.Properties.Error]            = OpenIdConnectConstants.Errors.LoginRequired,
                        [OpenIdConnectConstants.Properties.ErrorDescription] = "The user is not logged in."
                    });

                    // Ask OpenIddict to return a login_required error to the client application.
                    return(Forbid(properties, OpenIdConnectServerDefaults.AuthenticationScheme));
                }

                return(Challenge());
            }

            // Retrieve the profile of the logged in user.
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                return(_notice.Error(this, OpenIdConnectConstants.Errors.ServerError));
            }

            // Create a new authentication ticket.
            var ticket = await CreateTicketAsync(request, user);

            // Returning a SignInResult will ask OpenIddict to issue the appropriate access/identity tokens.
            return(SignIn(ticket.Principal, ticket.Properties, ticket.AuthenticationScheme));
        }
Пример #2
0
        public async Task <IActionResult> EditUserInfo()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                await _signInManager.SignOutAsync();

                return(_notice.Error(this));
            }

            var model = new EditUserInfoViewModel
            {
                UserName       = user.UserName,
                Logins         = await _userManager.GetLoginsAsync(user),
                Email          = user.Email,
                EmailConfirmed = user.EmailConfirmed,
                FullName       = user.FullName,
                NickName       = user.NickName
            };

            return(View(model));
        }
Пример #3
0
        public async Task <IActionResult> EditUserInfo()
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                await _signInManager.SignOutAsync();

                return(_notice.Error(this));
            }

            var model = new EditUserInfoViewModel
            {
                UserName       = user.UserName,
                Logins         = await _userManager.GetLoginsAsync(user),
                Email          = user.Email,
                EmailConfirmed = user.EmailConfirmed,
                FullName       = user.FullName,

                FavColor = user.FavColor // !! ADDING FIELDS: If you want users to be able to edit field
            };

            return(View(model));
        }