本文整理汇总了C#中UserService.CreateIdentity方法的典型用法代码示例。如果您正苦于以下问题:C# UserService.CreateIdentity方法的具体用法?C# UserService.CreateIdentity怎么用?C# UserService.CreateIdentity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类UserService
的用法示例。
在下文中一共展示了UserService.CreateIdentity方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Login
public ActionResult Login(LoginViewModel loginViewModel)
{
InterfaceUserService userService = new UserService();
if (ModelState.IsValid)
{
var _user = userService.Find(loginViewModel.UserName);
if (_user == null) ModelState.AddModelError("UserName", "用户名不存在");
else if (_user.Password == Common.Security.Sha256(loginViewModel.Password))
{
var _identity = userService.CreateIdentity(_user, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(new AuthenticationProperties() { IsPersistent = loginViewModel.RememberMe }, _identity);
return RedirectToAction("Index", "Home");
}
else ModelState.AddModelError("Password", "密码错误");
}
return View();
}
示例2: Register
public ActionResult Register(RegisterViewModel register)
{
InterfaceUserService userService = new UserService();
if (TempData["VerficationCode"] == null || TempData["VerficationCode"].ToString() != register.VerificationCode.ToUpper())
{
ModelState.AddModelError("VerficationCode", "验证码不正确");
return View(register);
}
if (ModelState.IsValid)
{
if (userService.Exist(register.UserName)) ModelState.AddModelError("UserName", "用户名已存在");
else
{
User _user = new User()
{
UserName = register.UserName,
//默认用户组代码写这里
DisplayName = register.DisplayName,
Password = Security.Sha256(register.Password),
//邮箱验证与邮箱唯一性问题
Email = register.Email,
//用户状态问题
Status = 0,
LoginIP = "",
LoginTime = DateTime.Now,
RegistrationTime = DateTime.Now
};
_user = userService.Add(_user);
if (_user.UserID > 0)
{
var _identity = userService.CreateIdentity(_user, DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie);
AuthenticationManager.SignIn(_identity);
return RedirectToAction("Index", "Home");
}
else { ModelState.AddModelError("", "注册失败!"); }
}
}
return View(register);
}