本文整理汇总了C#中IAuthenticationManager.SignIn方法的典型用法代码示例。如果您正苦于以下问题:C# IAuthenticationManager.SignIn方法的具体用法?C# IAuthenticationManager.SignIn怎么用?C# IAuthenticationManager.SignIn使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IAuthenticationManager
的用法示例。
在下文中一共展示了IAuthenticationManager.SignIn方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Login
public LoginResult Login(IAuthenticationManager authenticationManager, string email, string password, bool rememberMe)
{
bool isValid = this._queryDispatcher.Dispatch<bool, ValidateLoginQuery>(new ValidateLoginQuery(email, password, Role.Admin));
if (isValid)
{
Member member = this._queryDispatcher.Dispatch<Member, GetMemberByEmailQuery>(new GetMemberByEmailQuery(email));
var identity = new ClaimsIdentity(new[] { new Claim(ClaimTypes.Name, member.Guid.ToString()), }, DefaultAuthenticationTypes.ApplicationCookie, ClaimTypes.Name, ClaimTypes.Role);
// if you want roles, just add as many as you want here (for loop maybe?)
identity.AddClaim(new Claim(ClaimTypes.Role, "admin"));
// tell OWIN the identity provider, optional
// identity.AddClaim(new Claim(IdentityProvider, "Simplest Auth"));
authenticationManager.SignIn(new AuthenticationProperties
{
IsPersistent = rememberMe
}, identity);
return LoginResult.Success();
}
return LoginResult.InvalidUsernamePassword();
}
示例2: Login
public OperationResult<bool> Login(LoginViewModel loginViewModel, IAuthenticationManager authentication)
{
var identity = this.loginService.GetUserIndentity(loginViewModel);
var userIdentity = identity.Result;
authentication.SignIn(new AuthenticationProperties { IsPersistent = loginViewModel.RememberMe }, userIdentity);
return new OperationResult<bool>(true);
}
示例3: LoginAsync
//Аутентификация пользователя
public async Task<string> LoginAsync(LoginUserModel userLogin, IAuthenticationManager authenticationManager)
{
CatalogUser user = await _userManager.FindAsync(userLogin.UserName, userLogin.Password);
if (user == null)
{
return "Неверный логин или пароль";
}
else if (user.Activated == false)
{
return "Ваша учётная запись ещё не активирована администратором.";
}
else
{
ClaimsIdentity claim = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignOut();
authenticationManager.SignIn(new AuthenticationProperties
{
IsPersistent = userLogin.RememberMe,
}, claim);
return null;
}
}
示例4: SignInAsync
private async Task SignInAsync(ApplicationUser user, bool isPersistent, IAuthenticationManager authenticationManager)
{
authenticationManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
var identity = await UserManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = isPersistent }, identity);
}
示例5: SignInAsync
public static async Task SignInAsync(IAuthenticationManager authManager, ApplicationUserManager userManager,
User user, bool isPersistent)
{
authManager.SignOut(DefaultAuthenticationTypes.ExternalCookie);
authManager.SignIn(new AuthenticationProperties {IsPersistent = isPersistent},
await user.GenerateUserIdentityAsync(userManager));
}
示例6: LoginAsync
public async Task<string> LoginAsync(UserLogin userLogin, IAuthenticationManager authenticationManager)
{
SchoolUser user = await _userManager.FindAsync(userLogin.UserName, userLogin.Password);
if (user == null)
{
return "Неверный логин или пароль";
}
else
{
ClaimsIdentity claim = await _userManager.CreateIdentityAsync(user, DefaultAuthenticationTypes.ApplicationCookie);
authenticationManager.SignOut();
authenticationManager.SignIn(new AuthenticationProperties
{
IsPersistent = userLogin.RememberMe,
}, claim);
return null;
}
}
示例7: Authorize
// Authorize 操作是当你访问任何
// 受保护的 Web API 时调用的终结点。如果用户未登录,则将被重定向到
// Login 页。在成功登录后,你可以调用 Web API。
public void Authorize(IPrincipal User, IAuthenticationManager AuthenticationManager)
{
var claims = new ClaimsPrincipal(User).Claims.ToArray();
var identity = new ClaimsIdentity(claims, "Bearer");
AuthenticationManager.SignIn(identity);
}