本文整理汇总了C#中cloudscribe.Core.Models.SiteUser类的典型用法代码示例。如果您正苦于以下问题:C# SiteUser类的具体用法?C# SiteUser怎么用?C# SiteUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SiteUser类属于cloudscribe.Core.Models命名空间,在下文中一共展示了SiteUser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: BuildInitialAdmin
public static SiteUser BuildInitialAdmin()
{
var adminUser = new SiteUser();
adminUser.Email = "[email protected]";
adminUser.NormalizedEmail = adminUser.Email.ToUpperInvariant();
adminUser.DisplayName = "Admin";
adminUser.UserName = "admin";
adminUser.EmailConfirmed = true;
adminUser.AccountApproved = true;
// clear text password will be hashed upon login
// this format allows migrating from mojoportal
adminUser.PasswordHash = "admin||0"; //pwd/salt/format
return adminUser;
}
开发者ID:joeaudette,项目名称:cloudscribe,代码行数:17,代码来源:InitialData.cs
示例2: FromISiteUser
public static SiteUser FromISiteUser(ISiteUser user)
{
SiteUser u = new SiteUser();
u.AccountApproved = user.AccountApproved;
u.AuthorBio = user.AuthorBio;
u.AvatarUrl = user.AvatarUrl;
u.Comment = user.Comment;
u.Country = user.Country;
u.CreatedUtc = user.CreatedUtc;
u.DateOfBirth = user.DateOfBirth;
u.DisplayInMemberList = user.DisplayInMemberList;
u.DisplayName = user.DisplayName;
u.Email = user.Email;
u.EmailChangeGuid = user.EmailChangeGuid;
u.EmailConfirmed = user.EmailConfirmed;
u.FailedPasswordAnswerAttemptCount = user.FailedPasswordAnswerAttemptCount;
u.FailedPasswordAnswerAttemptWindowStart = user.FailedPasswordAnswerAttemptWindowStart;
u.FailedPasswordAttemptCount = user.FailedPasswordAttemptCount;
u.FailedPasswordAttemptWindowStart = user.FailedPasswordAttemptWindowStart;
u.FirstName = user.FirstName;
u.Gender = user.Gender;
//u.Id = user.Id;
u.IsDeleted = user.IsDeleted;
u.IsLockedOut = user.IsLockedOut;
u.LastActivityDate = user.LastActivityDate;
u.LastLockoutDate = user.LastLockoutDate;
u.LastLoginDate = user.LastLoginDate;
u.LastName = user.LastName;
u.LastPasswordChangedDate = user.LastPasswordChangedDate;
u.LockoutEndDateUtc = user.LockoutEndDateUtc;
u.LoweredEmail = user.LoweredEmail;
u.MustChangePwd = user.MustChangePwd;
u.NewEmail = user.NewEmail;
u.PasswordHash = user.PasswordHash;
u.PasswordResetGuid = user.PasswordResetGuid;
u.PhoneNumber = user.PhoneNumber;
u.PhoneNumberConfirmed = user.PhoneNumberConfirmed;
u.RegisterConfirmGuid = user.RegisterConfirmGuid;
u.RolesChanged = user.RolesChanged;
u.SecurityStamp = user.SecurityStamp;
u.Signature = user.Signature;
u.SiteGuid = user.SiteGuid;
u.SiteId = user.SiteId;
u.State = user.State;
u.TimeZoneId = user.TimeZoneId;
u.Trusted = user.Trusted;
u.TwoFactorEnabled = user.TwoFactorEnabled;
u.UserGuid = user.UserGuid;
u.UserId = user.UserId;
u.UserName = user.UserName;
u.WebSiteUrl = user.WebSiteUrl;
return u;
}
开发者ID:ludev,项目名称:cloudscribe,代码行数:55,代码来源:SiteUser.cs
示例3: FetchByLoginName
public async Task<ISiteUser> FetchByLoginName(int siteId, string userName, bool allowEmailFallback)
{
using (DbDataReader reader = await dbSiteUser.GetSingleUserByLoginName(siteId, userName, allowEmailFallback))
{
if (reader.Read())
{
SiteUser user = new SiteUser();
user.LoadFromReader(reader);
return user;
}
}
return null;
}
开发者ID:freemsly,项目名称:cloudscribe,代码行数:17,代码来源:UserRepository.cs
示例4: FetchByConfirmationGuid
public async Task<ISiteUser> FetchByConfirmationGuid(int siteId, Guid confirmGuid)
{
using (DbDataReader reader = await dbSiteUser.GetUserByRegistrationGuid(siteId, confirmGuid))
{
if (reader.Read())
{
SiteUser user = new SiteUser();
user.LoadFromReader(reader);
if (user.SiteId == siteId) { return user; }
}
}
return null;
}
开发者ID:freemsly,项目名称:cloudscribe,代码行数:17,代码来源:UserRepository.cs
示例5: GetUsersForClaim
public async Task<IList<ISiteUser>> GetUsersForClaim(
int siteId,
string claimType,
string claimValue)
{
IList<ISiteUser> users = new List<ISiteUser>();
using (DbDataReader reader = await dbUserClaims.GetUsersByClaim(siteId, claimType, claimValue))
{
while (reader.Read())
{
SiteUser user = new SiteUser();
user.LoadFromReader(reader);
users.Add(user);
}
}
return users;
}
开发者ID:freemsly,项目名称:cloudscribe,代码行数:21,代码来源:UserRepository.cs
示例6: ExternalLoginConfirmation
public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
{
log.LogDebug("ExternalLoginConfirmation called with returnurl " + returnUrl);
//if (signInManager.IsSignedIn(User))
//{
// return RedirectToAction("Index", "Manage");
//}
if (ModelState.IsValid)
{
// Get the information about the user from the external login provider
var info = await signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
return View("ExternalLoginFailure");
}
var userName = model.Email.Replace("@", string.Empty).Replace(".", string.Empty);
var userNameAvailable = await userManager.LoginIsAvailable(Guid.Empty, userName);
if (!userNameAvailable)
{
userName = model.Email;
}
var user = new SiteUser {
SiteId = Site.Id,
UserName = userName,
Email = model.Email,
AccountApproved = Site.RequireApprovalBeforeLogin ? false : true
};
var result = await userManager.CreateAsync(user);
if (result.Succeeded)
{
log.LogDebug("ExternalLoginConfirmation user created ");
await ipAddressTracker.TackUserIpAddress(Site.Id, user.Id);
result = await userManager.AddLoginAsync(user, info);
if (result.Succeeded)
{
log.LogDebug("ExternalLoginConfirmation AddLoginAsync succeeded ");
if (Site.RequireConfirmedEmail) // require email confirmation
{
var code = await userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.Action(new UrlActionContext
{
Action = "ConfirmEmail",
Controller = "Account",
Values = new { userId = user.Id.ToString(), code = code },
Protocol = HttpContext.Request.Scheme
});
emailSender.SendAccountConfirmationEmailAsync(
Site,
model.Email,
sr["Confirm your account"],
callbackUrl).Forget();
// this is needed to clear the external cookie - wasn't needed in rc2
await signInManager.SignOutAsync();
if (this.SessionIsAvailable())
{
this.AlertSuccess(sr["Please check your email inbox, we just sent you a link that you need to click to confirm your account"], true);
return Redirect("/");
}
else
{
return RedirectToAction("EmailConfirmationRequired", new { userId = user.Id, didSend = true });
}
}
else
{
if (Site.RequireApprovalBeforeLogin)
{
emailSender.AccountPendingApprovalAdminNotification(Site, user).Forget();
// this is needed to clear the external cookie - wasn't needed in rc2
await signInManager.SignOutAsync();
return RedirectToAction("PendingApproval", new { userId = user.Id, didSend = true });
}
else
{
await signInManager.SignInAsync(user, isPersistent: false);
if (!string.IsNullOrEmpty(returnUrl))
{
return LocalRedirect(returnUrl);
}
return this.RedirectToSiteRoot(Site);
}
}
//.........这里部分代码省略.........
开发者ID:joeaudette,项目名称:cloudscribe,代码行数:101,代码来源:AccountController.cs
示例7: ExternalLoginConfirmation
public async Task<IActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
{
log.LogInformation("ExternalLoginConfirmation called with returnurl " + returnUrl);
if (User.IsSignedIn())
{
return RedirectToAction("Index", "Manage");
}
if (ModelState.IsValid)
{
// Get the information about the user from the external login provider
var info = await signInManager.GetExternalLoginInfoAsync();
if (info == null)
{
return View("ExternalLoginFailure");
}
var user = new SiteUser {
SiteGuid = Site.SiteGuid,
SiteId = Site.SiteId,
UserName = model.Email,
Email = model.Email
};
var result = await userManager.CreateAsync(user);
if (result.Succeeded)
{
log.LogInformation("ExternalLoginConfirmation user created ");
result = await userManager.AddLoginAsync(user, info);
if (result.Succeeded)
{
log.LogInformation("ExternalLoginConfirmation AddLoginAsync succeeded ");
await signInManager.SignInAsync(user, isPersistent: false);
return this.RedirectToLocal(returnUrl);
}
else
{
log.LogInformation("ExternalLoginConfirmation AddLoginAsync failed ");
}
}
else
{
log.LogInformation("ExternalLoginConfirmation failed to user created ");
}
AddErrors(result);
}
else
{
log.LogInformation("ExternalLoginConfirmation called with ModelStateInvalid ");
}
ViewData["ReturnUrl"] = returnUrl;
return View(model);
}
开发者ID:alfkonee,项目名称:cloudscribe,代码行数:55,代码来源:AccountController.cs
示例8: UserEdit
public async Task<IActionResult> UserEdit(EditUserViewModel model)
{
ISiteSettings selectedSite;
// only server admin site can edit other sites settings
if ((model.SiteGuid != siteManager.CurrentSite.SiteGuid) && (model.SiteGuid != Guid.Empty) && (siteManager.CurrentSite.IsServerAdminSite))
{
selectedSite = await siteManager.Fetch(model.SiteGuid);
}
else
{
selectedSite = siteManager.CurrentSite;
}
ViewData["Title"] = "New User";
if (ModelState.IsValid)
{
if (model.UserId > -1)
{
//editing an existing user
ISiteUser user = await UserManager.Fetch(selectedSite.SiteId, model.UserId);
if (user != null)
{
user.Email = model.Email;
user.FirstName = model.FirstName;
user.LastName = model.LastName;
user.UserName = model.LoginName;
user.DisplayName = model.DisplayName;
if (model.DateOfBirth.HasValue)
{
user.DateOfBirth = model.DateOfBirth.Value;
}
else
{
user.DateOfBirth = DateTime.MinValue;
}
bool result = await UserManager.Save(user);
if (result)
{
this.AlertSuccess(string.Format("user account for <b>{0}</b> was successfully updated.",
user.DisplayName), true);
}
return RedirectToAction("Index", "UserAdmin");
}
}
else
{
var user = new SiteUser
{
SiteId = selectedSite.SiteId,
SiteGuid = selectedSite.SiteGuid,
UserName = model.LoginName,
Email = model.Email,
FirstName = model.FirstName,
LastName = model.LastName,
DisplayName = model.DisplayName
};
if (model.DateOfBirth.HasValue)
{
user.DateOfBirth = model.DateOfBirth.Value;
}
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
this.AlertSuccess(string.Format("user account for <b>{0}</b> was successfully created.",
user.DisplayName), true);
return RedirectToAction("Index", "UserAdmin");
}
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
开发者ID:Tinkerc,项目名称:cloudscribe,代码行数:84,代码来源:UserAdminController.cs
示例9: Fetch
public async Task<ISiteUser> Fetch(int siteId, string email)
{
if (multiTenantOptions.UseRelatedSitesMode) { siteId = multiTenantOptions.RelatedSiteId; }
using (DbDataReader reader = await dbSiteUser.GetSingleUser(siteId, email))
{
if (reader.Read())
{
SiteUser user = new SiteUser();
user.LoadFromReader(reader);
return user;
}
}
return null;
}
开发者ID:okusnadi,项目名称:cloudscribe,代码行数:19,代码来源:UserRepository.cs
示例10: GetUsersForClaim
public async Task<IList<ISiteUser>> GetUsersForClaim(
int siteId,
string claimType,
string claimValue)
{
IList<ISiteUser> users = new List<ISiteUser>();
if (multiTenantOptions.UseRelatedSitesMode) { siteId = multiTenantOptions.RelatedSiteId; }
using (DbDataReader reader = await dbUserClaims.GetUsersByClaim(siteId, claimType, claimValue))
{
while (reader.Read())
{
SiteUser user = new SiteUser();
user.LoadFromReader(reader);
users.Add(user);
}
}
return users;
}
开发者ID:okusnadi,项目名称:cloudscribe,代码行数:23,代码来源:UserRepository.cs
示例11: Fetch
public async Task<ISiteUser> Fetch(int siteId, Guid userGuid, CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
using (DbDataReader reader = dbSiteUser.GetSingleUser(userGuid))
{
if (reader.Read())
{
SiteUser user = new SiteUser();
user.LoadFromReader(reader);
if (user.SiteId == siteId) { return user; }
}
}
return null;
}
开发者ID:ludev,项目名称:cloudscribe,代码行数:19,代码来源:UserRepository.cs
示例12: EnsureData
//.........这里部分代码省略.........
adminRole.RoleName = "Admins";
adminRole.DisplayName = "Administrators";
adminRole.SiteId = site.SiteId;
adminRole.SiteGuid = site.SiteGuid;
db.Roles.Add(adminRole);
//rowsAffected = await db.SaveChangesAsync();
SiteRole roleAdminRole = new SiteRole();
roleAdminRole.RoleId = 0;
roleAdminRole.RoleGuid = Guid.NewGuid();
roleAdminRole.RoleName = "Role Admins";
roleAdminRole.DisplayName = "Role Administrators";
roleAdminRole.SiteId = site.SiteId;
roleAdminRole.SiteGuid = site.SiteGuid;
db.Roles.Add(roleAdminRole);
//rowsAffected = await db.SaveChangesAsync();
SiteRole contentAdminRole = new SiteRole();
contentAdminRole.RoleId = 0;
contentAdminRole.RoleGuid = Guid.NewGuid();
contentAdminRole.RoleName = "Content Administrators";
contentAdminRole.DisplayName = "Content Administrators";
contentAdminRole.SiteId = site.SiteId;
contentAdminRole.SiteGuid = site.SiteGuid;
db.Roles.Add(contentAdminRole);
SiteRole authenticatedUserRole = new SiteRole();
authenticatedUserRole.RoleId = 0;
authenticatedUserRole.RoleGuid = Guid.NewGuid();
authenticatedUserRole.RoleName = "Authenticated Users";
authenticatedUserRole.DisplayName = "Authenticated Users";
authenticatedUserRole.SiteId = site.SiteId;
authenticatedUserRole.SiteGuid = site.SiteGuid;
db.Roles.Add(authenticatedUserRole);
rowsAffected = await db.SaveChangesAsync();
}
}
// ensure admin user
count = await db.Users.CountAsync<SiteUser>();
if (count == 0)
{
SiteSettings site = await db.Sites.SingleOrDefaultAsync<SiteSettings>(
s => s.SiteId > 0 && s.IsServerAdminSite == true);
if (site != null)
{
SiteRole role
= await db.Roles.SingleOrDefaultAsync(
x => x.SiteId == site.SiteId && x.RoleName == "Admins");
if(role != null)
{
SiteUser adminUser = new SiteUser();
adminUser.SiteId = site.SiteId;
adminUser.SiteGuid = site.SiteGuid;
adminUser.Email = "[email protected]";
adminUser.LoweredEmail = adminUser.Email;
adminUser.DisplayName = "Admin";
adminUser.UserName = "admin";
adminUser.UserId = 0;
adminUser.UserGuid = Guid.NewGuid();
adminUser.EmailConfirmed = true;
adminUser.AccountApproved = true;
// clear text password will be hashed upon login
// this format allows migrating from mojoportal
adminUser.PasswordHash = "admin||0"; //pwd/salt/format
db.Users.Add(adminUser);
rowsAffected = await db.SaveChangesAsync();
if(rowsAffected > 0 && adminUser.UserId > -1)
{
UserRole ur = new UserRole();
ur.Id = 0;
ur.RoleGuid = role.RoleGuid;
ur.RoleId = role.RoleId;
ur.UserGuid = adminUser.UserGuid;
ur.UserId = adminUser.UserId;
db.UserRoles.Add(ur);
rowsAffected = await db.SaveChangesAsync();
}
}
}
}
}
开发者ID:ludev,项目名称:cloudscribe,代码行数:101,代码来源:InitialData.cs
示例13: CreateRequiredRolesAndAdminUser
public async Task<bool> CreateRequiredRolesAndAdminUser(
SiteSettings site)
{
SiteRole adminRole = new SiteRole();
adminRole.DisplayName = "Admins";
//adminRole.DisplayName = "Administrators";
adminRole.SiteId = site.SiteId;
adminRole.SiteGuid = site.SiteGuid;
bool result = await userRepo.SaveRole(adminRole);
adminRole.DisplayName = "Administrators";
result = await userRepo.SaveRole(adminRole);
SiteRole roleAdminRole = new SiteRole();
roleAdminRole.DisplayName = "Role Admins";
roleAdminRole.SiteId = site.SiteId;
roleAdminRole.SiteGuid = site.SiteGuid;
result = await userRepo.SaveRole(roleAdminRole);
roleAdminRole.DisplayName = "Role Administrators";
result = await userRepo.SaveRole(roleAdminRole);
SiteRole contentAdminRole = new SiteRole();
contentAdminRole.DisplayName = "Content Administrators";
contentAdminRole.SiteId = site.SiteId;
contentAdminRole.SiteGuid = site.SiteGuid;
result = await userRepo.SaveRole(contentAdminRole);
SiteRole authenticatedUserRole = new SiteRole();
authenticatedUserRole.DisplayName = "Authenticated Users";
authenticatedUserRole.SiteId = site.SiteId;
authenticatedUserRole.SiteGuid = site.SiteGuid;
result = await userRepo.SaveRole(authenticatedUserRole);
//SiteRole newsletterAdminRole = new SiteRole();
//newsletterAdminRole.DisplayName = "Newsletter Administrators";
//newsletterAdminRole.SiteId = site.SiteId;
//newsletterAdminRole.SiteGuid = site.SiteGuid;
//userRepository.SaveRole(newsletterAdminRole);
// if using related sites mode there is a problem if we already have user [email protected]
// and we create another one in the child site with the same email and login so we need to make it different
// we could just skip creating this user since in related sites mode all users come from the first site
// but then if the config were changed to not related sites mode there would be no admin user
// so in related sites mode we create one only as a backup in case settings are changed later
int countOfSites = await siteRepo.GetCount();
string siteDifferentiator = string.Empty;
if (
(countOfSites >= 1)
&& (multiTenantOptions.UseRelatedSitesMode)
)
{
if (site.SiteId > 1)
{
siteDifferentiator = site.SiteId.ToInvariantString();
}
}
//mojoMembershipProvider membership = Membership.Provider as mojoMembershipProvider;
//bool overridRelatedSiteMode = true;
SiteUser adminUser = new SiteUser();
adminUser.SiteId = site.SiteId;
adminUser.SiteGuid = site.SiteGuid;
adminUser.Email = "admin" + siteDifferentiator + "@admin.com";
adminUser.DisplayName = "Admin";
adminUser.UserName = "admin" + siteDifferentiator;
adminUser.EmailConfirmed = true;
adminUser.ApprovedForLogin = true;
adminUser.Password = "admin";
adminUser.PasswordFormat = 0;
//if (membership != null)
//{
// adminUser.Password = membership.EncodePassword(site, adminUser, "admin");
//}
adminUser.PasswordQuestion = "What is your user name?";
adminUser.PasswordAnswer = "admin";
result = await userRepo.Save(adminUser);
//siteUserManager.AddPassword(adminUser.UserGuid.ToString(), "admin");
//siteUserManager.Create(adminUser, "admin");
//var result = siteUserManager.CreateAsync(adminUser, "admin");
//if (result.Succeeded)
//{
//}
result = await userRepo.AddUserToRole(
adminRole.RoleId,
adminRole.RoleGuid,
adminUser.UserId,
adminUser.UserGuid);
return result;
}
开发者ID:okusnadi,项目名称:cloudscribe,代码行数:98,代码来源:SiteManager.cs
示例14: FetchByConfirmationGuid
public async Task<ISiteUser> FetchByConfirmationGuid(int siteId, Guid confirmGuid)
{
if (multiTenantOptions.UseRelatedSitesMode) { siteId = multiTenantOptions.RelatedSiteId; }
using (DbDataReader reader = dbSiteUser.GetUserByRegistrationGuid(siteId, confirmGuid))
{
if (reader.Read())
{
SiteUser user = new SiteUser();
user.LoadFromReader(reader);
if (user.SiteId == siteId) { return user; }
}
}
return null;
}
开发者ID:okusnadi,项目名称:cloudscribe,代码行数:19,代码来源:UserRepository.cs
示例15: Fetch
public async Task<ISiteUser> Fetch(
int siteId,
string email,
CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
using (DbDataReader reader = await dbSiteUser.GetSingleUser(
siteId,
email,
cancellationToken))
{
if (reader.Read())
{
SiteUser user = new SiteUser();
user.LoadFromReader(reader);
return user;
}
}
return null;
}
开发者ID:alfkonee,项目名称:cloudscribe,代码行数:24,代码来源:UserRepository.cs
示例16: FetchByLoginName
public async Task<ISiteUser> FetchByLoginName(
int siteId,
string userName,
bool allowEmailFallback,
CancellationToken cancellationToken = default(CancellationToken))
{
cancellationToken.ThrowIfCancellationRequested();
using (DbDataReader reader = await dbSiteUser.GetSingleUserByLoginName(
siteId,
userName,
allowEmailFallback,
cancellationToken))
{
if (reader.Read())
{
SiteUser user = new SiteUser();
user.LoadFromReader(reader);
return user;
}
}
return null;
}
开发者ID:alfkonee,项目名称:cloudscribe,代码行数:26,代码来源:UserRepository.cs
示例17: FetchByLoginName
public async Task<ISiteUser> FetchByLoginName(int siteId, string userName, bool allowEmailFallback)
{
if (multiTenantOptions.UseRelatedSitesMode) { siteId = multiTenantOptions.RelatedSiteId; }
using (DbDataReader reader = await dbSiteUser.GetSingleUserByLoginName(siteId, userName, allowEmailFallback))
{
if (reader.Read())
{
SiteUser user = new SiteUser();
user.LoadFromReader(reader);
return user;
}
}
return null;
}
开发者ID:okusnadi,项目名称:cloudscribe,代码行数:19,代码来源:UserRepository.cs
示例18: Register
public async Task<IActionResult> Register(RegisterViewModel model)
{
ViewData["Title"] = "Register";
if ((Site.CaptchaOnRegistration)&& (Site.RecaptchaPublicKey.Length > 0))
{
model.RecaptchaSiteKey = Site.RecaptchaPublicKey;
}
model.RegistrationPreamble = Site.RegistrationPreamble;
model.RegistrationAgreement = Site.RegistrationAgreement;
bool isValid = ModelState.IsValid;
if (isValid)
{
if ((Site.CaptchaOnRegistration)&& (Site.RecaptchaPublicKey.Length > 0))
{
string recpatchaSecretKey = Site.RecaptchaPrivateKey;
var captchaResponse = await this.ValidateRecaptcha(Request, recpatchaSecretKey);
if (!captchaResponse.Success)
{
//if (captchaResponse.ErrorCodes.Count <= 0)
//{
// return View(model);
//}
////TODO: log these errors rather than show them in the ui
//var error = captchaResponse.ErrorCodes[0].ToLower();
//switch (error)
//{
// case ("missing-input-secret"):
// ModelState.AddModelError("recaptchaerror", "The secret parameter is missing.");
// break;
// case ("invalid-input-secret"):
// ModelState.AddModelError("recaptchaerror", "The secret parameter is invalid or malformed.");
// break;
// case ("missing-input-response"):
// ModelState.AddModelError("recaptchaerror", "The response parameter is missing.");
// break;
// case ("invalid-input-response"):
// ModelState.AddModelError("recaptchaerror", "The response parameter is invalid or malformed.");
// break;
// default:
// ModelState.AddModelError("recaptchaerror", "Error occured. Please try again");
// break;
//}
ModelState.AddModelError("recaptchaerror", "reCAPTCHA Error occured. Please try again");
isValid = false;
}
}
//if (Site.RegistrationAgreement.Length > 0)
//{
// if (!model.AgreeToTerms)
// {
// ModelState.AddModelError("agreementerror", "You must agree to the terms");
// isValid = false;
// }
//}
if (!isValid)
{
return View(model);
}
var user = new SiteUser
{
UserName = model.LoginName.Length > 0? model.LoginName : model.Email.Replace("@",string.Empty).Replace(".",string.Empty),
Email = model.Email,
FirstName = model.FirstName,
LastName = model.LastName,
DisplayName = model.DisplayName
};
if (model.DateOfBirth.HasValue)
{
user.DateOfBirth = model.DateOfBirth.Value;
}
var result = await userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
if(Site.UseSecureRegistration) // require email confirmation
{
var code = await userManager.GenerateEmailConfirmationTokenAsync(user);
var callbackUrl = Url.Action("ConfirmEmail", "Account",
new { userId = user.Id, code = code },
protocol: HttpContext.Request.Scheme);
await emailSender.SendAccountConfirmationEmailAsync(
Site,
model.Email,
"Confirm your account",
//.........这里部分代码省略.........
开发者ID:alfkonee,项目名称:cloudscribe,代码行数:101,代码来源:AccountController.cs
示例19: Register
public async Task<IActionResult> Register(EditUserViewModel model)
{
ViewData["Title"] = "Register";
if ((Site.RequireCaptchaOnRegistration)&& (Site.RecaptchaPublicKey.Length > 0))
{
model.RecaptchaSiteKey = Site.RecaptchaPublicKey;
}
model.RegistrationPreamble = Site.RegistrationPreamble;
model.RegistrationAgreement = Site.RegistrationAgreement;
bool isValid = ModelState.IsValid;
if (isValid)
{
if ((Site.RequireCaptchaOnRegistration)&& (Site.RecaptchaPublicKey.Length > 0))
{
string recpatchaSecretKey = Site.RecaptchaPrivateKey;
var captchaResponse = await this.ValidateRecaptcha(Request, recpatchaSecretKey);
if (!captchaResponse.Success)
{
//if (captchaResponse.ErrorCodes.Count <= 0)
//{
// return View(model);
//}
////TODO: log these errors rather than show them in the ui
//var error = captchaResponse.ErrorCodes[0].ToLower();
//switch (error)
//{
// case ("missing-input-secret"):
// ModelState.AddModelError("recaptchaerror", "The secret parameter is missing.");
// break;
// case ("invalid-input-secret"):
// ModelState.AddModelError("recaptchaerror", "The secret parameter is invalid or malformed.");
// break;
// case ("missing-input-response"):
// ModelState.AddModelError("recaptchaerror", "The response parameter is missing.");
// break;
// case ("invalid-input-response"):
// ModelState.AddModelError("recaptchaerror", "The response parameter is invalid or malformed.");
// break;
// default:
// ModelState.AddModelError("recaptchaerror", "Error occured. Please try again");
// break;
//}
ModelState.AddModelError("recaptchaerror", "reCAPTCHA Error occured. Please try again");
isValid = false;
}
}
//if (Site.RegistrationAgreement.Length > 0)
//{
// if (!model.AgreeToTerms)
// {
// ModelState.AddModelError("agreementerror", "You must agree to the terms");
// isValid = false;
// }
//}
if (!isValid)
{
return View(model);
}
var user = new SiteUser
{
UserName = model.LoginName.Length > 0? model.LoginName : model.Email.Replace("@",string.Empty).Replace(".",string.Empty),
Email = model.Email,
FirstName = model.FirstName,
LastName = model.LastName,
DisplayName = model.DisplayName
};
if (model.DateOfBirth.HasValue)
{
user.DateOfBirth = model.DateOfBirth.Value;
}
var result = await userManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
// For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=532713
|
请发表评论