本文整理汇总了C#中IUserRepository.AddRole方法的典型用法代码示例。如果您正苦于以下问题:C# IUserRepository.AddRole方法的具体用法?C# IUserRepository.AddRole怎么用?C# IUserRepository.AddRole使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IUserRepository
的用法示例。
在下文中一共展示了IUserRepository.AddRole方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoginModule
public LoginModule(IUserRepository userRepository)
{
_user = userRepository;
Post["/login/token"] = x =>
{
if (string.IsNullOrWhiteSpace(Request.Form.token))
return
View["Login/Error",
new
{
Title = "Login Error",
Message = "Bad response from login provider - could not find login token."
}];
var response = new WebClient().DownloadString(string.Format("https://rpxnow.com/api/v2/auth_info?apiKey={0}&token={1}",apikey, Request.Form.token));
if (string.IsNullOrWhiteSpace(response))
return
View["Login/Error",
new
{
Title = "Login Error",
Message = "Bad response from login provider - could not find user."
}];
var j = JsonConvert.DeserializeObject<dynamic>(response);
if (j.stat.ToString() != "ok")
return
View["Login/Error",
new
{
Title = "Login Error",
Message = "Bad response from login provider."
}];
var userIdentity = j.profile.identifier.ToString();
var username = j.profile.preferredUsername.ToString();
string email = string.Empty;
if (j.profile.email != null)
email = j.profile.email.ToString();
var user = _user.GetUserFromUserIdentity(userIdentity);
if (user == null)
{
var u = new User
{
Id = Guid.NewGuid(),
Identity = userIdentity,
UserName = (!string.IsNullOrEmpty(username)) ? username : "New User " + _user.GetAll().Count(),
Email = (!string.IsNullOrEmpty(email)) ? email : "[email protected]",
Github = (!string.IsNullOrEmpty(username)) ? username : "",
IsActive = true,
};
if (!_user.GetAll().Any())
_user.AddRole(u, "Admin");
if (j.profile.photo != null)
u.AvatarUrl = j.profile.photo.ToString();
_user.Add(u);
return this.LoginAndRedirect(u.Id, DateTime.Now.AddDays(1), "/profile/edit");
}
return ModuleExtensions.Login(this, user.Id, DateTime.Now.AddDays(1), "/");
};
Get["/logout/"] = parameters => this.LogoutAndRedirect("/");
}