本文整理汇总了C#中ApplicationUser类的典型用法代码示例。如果您正苦于以下问题:C# ApplicationUser类的具体用法?C# ApplicationUser怎么用?C# ApplicationUser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ApplicationUser类属于命名空间,在下文中一共展示了ApplicationUser类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: CreateUser_Click
protected void CreateUser_Click(object sender, EventArgs e)
{
var manager = new UserManager();
var user = new ApplicationUser() { UserName = UserName.Text };
IdentityResult result = manager.Create(user, Password.Text);
if (result.Succeeded)
{
ApplicationUser newUser = manager.Find(UserName.Text, Password.Text);
var sa = new StoredAccount();
sa.CreateNewAccount(newUser.Id,Email.Text);
var returnUrl = Request.QueryString["ReturnUrl"];
IdentityHelper.SignIn(manager, user, isPersistent: false);
if (returnUrl == null)
{
IdentityHelper.RedirectToReturnUrl("~/Game/User-Home.aspx", Response);
}
else
{
IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
}
}
else
{
ErrorMessage.Text = result.Errors.FirstOrDefault();
}
}
开发者ID:masterhou,项目名称:webgl2012,代码行数:26,代码来源:Register.aspx.cs
示例2: CreateAndLoginUser
private void CreateAndLoginUser()
{
if (!IsValid)
{
return;
}
var manager = new UserManager();
var user = new ApplicationUser() { UserName = userName.Text };
IdentityResult result = manager.Create(user);
if (result.Succeeded)
{
var loginInfo = Context.GetOwinContext().Authentication.GetExternalLoginInfo();
if (loginInfo == null)
{
Response.Redirect("~/Account/Login");
return;
}
result = manager.AddLogin(user.Id, loginInfo.Login);
if (result.Succeeded)
{
IdentityHelper.SignIn(manager, user, isPersistent: false);
IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], Response);
return;
}
}
AddErrors(result);
}
开发者ID:NikolayKostadinov,项目名称:Homeworks,代码行数:27,代码来源:RegisterExternalLogin.aspx.cs
示例3: CreatePosting
// ************************
// Beer Postings Methods
// ************************
public BeerPosting CreatePosting(ApplicationUser owner, BeerPosting _newbeerposting)
{
context.BeerPostings.Add(_newbeerposting);
context.SaveChanges();
return _newbeerposting;
}
开发者ID:jlsears,项目名称:beerswap,代码行数:10,代码来源:BeerPostRepository.cs
示例4: Create
public ActionResult Create([DataSourceRequest]DataSourceRequest request, UserAdministrationModel model)
{
if (model != null && this.ModelState.IsValid)
{
var newUser = new ApplicationUser
{
UserName = model.UserName,
Email = model.Email,
FirstName = model.FirstName,
LastName = model.LastName,
CreatedOn = DateTime.Now
};
var password = string.IsNullOrEmpty(model.NewPassword) ? "123456" : model.NewPassword;
this.userManager.Create(newUser, password);
if (model.IsAdmin)
{
this.userManager.AddToRole(newUser.Id, ApplicationRoles.Admin);
}
if (model.IsArtist)
{
this.userManager.AddToRole(newUser.Id, ApplicationRoles.Artist);
}
if (model.IsDesigner)
{
this.userManager.AddToRole(newUser.Id, ApplicationRoles.Designer);
}
if (model.IsRegular)
{
this.userManager.AddToRole(newUser.Id, ApplicationRoles.Regular);
}
if (model.IsSeller)
{
this.userManager.AddToRole(newUser.Id, ApplicationRoles.Seller);
}
if (model.IsStudent)
{
this.userManager.AddToRole(newUser.Id, ApplicationRoles.Student);
}
if (model.IsTrainer)
{
this.userManager.AddToRole(newUser.Id, ApplicationRoles.Trainer);
}
model.Id = newUser.Id;
model.NewPassword = string.Empty;
return this.GridOperationObject(model, request);
}
return null;
}
开发者ID:IvoPaunov,项目名称:Course-Project-ASP.NET-MVC,代码行数:60,代码来源:UsersController.cs
示例5: CreateUser
public static ApplicationUser CreateUser(UserManager<ApplicationUser> userManager, string email, string firstName, string lastName,
string password, bool lockOutEnabled)
{
var user = userManager.FindByName(email);
if (user == null)
{
user = new ApplicationUser
{
UserName = email,
Email = email,
FirstName = firstName,
LastName = lastName,
EmailConfirmed = true
};
try
{
userManager.Create(user, password);
}
catch (Exception ex)
{
Log4NetHelper.Log("Error creating Admin User", LogLevel.ERROR, "AspNetUser", 1, "none", ex);
}
userManager.SetLockoutEnabled(user.Id, lockOutEnabled);
}
return user;
}
开发者ID:rswetnam,项目名称:GoodBoating,代码行数:27,代码来源:SeedServices.cs
示例6: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser() { UserName = model.UserName };
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, isPersistent: false);
var service = new Service();
User register = new User();
register.Active = true;
register.BirthYear = model.BirthYear;
register.DisplayName = model.DisplayName;
register.Email = model.Email;
register.Gender = model.Gender;
register.UserName = model.UserName;
service.CreateUser(ref register);
DisplayWelcomeMessage(register);
return RedirectToAction("Index", "User");
}
else
{
ModelState.AddModelError("UserName", "That username is already taken");
AddErrors(result);
}
}
// If we got this far, something failed, redisplay form.
return View(model);
}
开发者ID:kthorri,项目名称:doStuff,代码行数:33,代码来源:AccountController.cs
示例7: EditUserViewModel
// Allow Initialization with an instance of ApplicationUser:
public EditUserViewModel(ApplicationUser user)
{
this.UserName = user.UserName;
this.FirstName = user.FirstName;
this.LastName = user.LastName;
this.Email = user.Email;
}
开发者ID:futurify-tainguyen,项目名称:test,代码行数:8,代码来源:AccountViewModels.cs
示例8: AddAllUserCohortMeetings
private static void AddAllUserCohortMeetings(ApplicationDbContext context, ApplicationUser user, int utcOffset, ref List<MeetingViewModel> meetingDtos)
{
var enrollmentsWithThisUser = context.Courses.SelectMany(u => u.Enrollments.Where(e => e.ApplicationUserId == user.Id));
foreach (var enrollment in enrollmentsWithThisUser)
{
//Get all meetings with this enrollment where its cohort has a meeting that is in the future
Enrollment enrollment1 = enrollment;
var cohortMeetings = context.Meetings.Where(m => m.CourseId == enrollment1.CourseId);
foreach (var meeting in cohortMeetings)
{
var meetingToAdd = new MeetingViewModel
{
Id = meeting.Id,
Title = meeting.Title,
Start = DateTime.SpecifyKind(meeting.Start, DateTimeKind.Utc).AddMinutes(utcOffset),
End = DateTime.SpecifyKind(meeting.End, DateTimeKind.Utc).AddMinutes(utcOffset),
Description = meeting.Description,
IsAllDay = meeting.IsAllDay,
RecurrenceRule = meeting.RecurrenceRule,
RecurrenceException = meeting.RecurrenceException,
RecurrenceId = meeting.RecurrenceId,
CourseId = meeting.CourseId,
GtmUrl = meeting.GtmUrl
};
meetingDtos.Add(meetingToAdd);
}
}
}
开发者ID:rswetnam,项目名称:GoodBoating,代码行数:29,代码来源:MeetingUtilities.cs
示例9: Edit
public async Task<ActionResult> Edit (string id, ApplicationUser applicationUser)
{
try
{
var user = await _userManager.FindByIdAsync(id);
if(applicationUser.LockoutEnabled == true)
{
user.LockoutEnd = DateTime.UtcNow.AddYears(100);
}
else
{
user.LockoutEnd = DateTime.UtcNow;
}
user.LockoutEnabled = applicationUser.LockoutEnabled;
await _userManager.UpdateAsync(user);
return RedirectToAction("Index");
}
catch (Exception)
{
ModelState.AddModelError(string.Empty, "Unable to save changes.");
}
return View(applicationUser);
}
开发者ID:COMP4976MVC6,项目名称:TeamMVC6,代码行数:26,代码来源:UsersController.cs
示例10: UserCohortMeetingsToday
//public static IEnumerable<MeetingViewModel> UserMeetingsTodayAll(ApplicationDbContext context, ApplicationUser user, Double utcOffset)
//{
// var meetingDtos = new List<MeetingViewModel>();
// UserCohortMeetingsToday(context, user, utcOffset, ref meetingDtos);
// MeetingsServices.UserPrivateMeetingsToday(context, user, utcOffset, ref meetingDtos);
// return meetingDtos;
//}
private static void UserCohortMeetingsToday(ApplicationDbContext context, ApplicationUser user, Double utcOffset, ref List<MeetingViewModel> meetingDtos)
{
var enrollmentsWithThisUser = context.Courses.SelectMany(u => u.Enrollments.Where(e => e.ApplicationUserId == user.Id));
var localNow = DateTime.UtcNow.AddMinutes(utcOffset);
var localTodayDate = localNow.ToShortDateString();
//foreach (var enrollment in enrollmentsWithThisUser)
//{
// //Get all meetings with this enrollment where its cohort has a meeting that is in the future
// var enrollment1 = enrollment;
// //var cohortMeetings = context.Meetings.ToList().Where(m => m.CourseId == enrollment1.CourseId && m.Start.AddMinutes(utcOffset).ToShortDateString()==rightNow);
// var cohortMeetings = context.Meetings.Where(m => m.CourseId == enrollment1.CourseId).OrderBy(m => m.Start);
// foreach (var meeting in cohortMeetings)
// {
// if (meeting.Start.AddMinutes(utcOffset).ToShortDateString() == localTodayDate)
// {
// var meetingToAdd = new MeetingViewModel
// {
// Id = meeting.Id,
// Title = meeting.Title,
// Start = DateTime.SpecifyKind(meeting.Start, DateTimeKind.Utc).AddMinutes(utcOffset),
// End = meeting.End.AddMinutes(utcOffset),
// Description = meeting.Description,
// IsAllDay = meeting.IsAllDay,
// RecurrenceRule = meeting.RecurrenceRule,
// RecurrenceException = meeting.RecurrenceException,
// RecurrenceId = meeting.RecurrenceId,
// CourseId = meeting.CourseId,
// GtmUrl = meeting.GtmUrl
// };
// meetingDtos.Add(meetingToAdd);
// }
// }
//}
}
开发者ID:rswetnam,项目名称:GoodBoating,代码行数:44,代码来源:MeetingUtilities.cs
示例11: Create
public ActionResult Create([Bind(Include = "Id,Name,Address,Phone,Email,VendorId,AspId")] VendorUser vendorUser)
{
//if (ModelState.IsValid)
//{
// db.VendorUsers.Add(vendorUser);
// db.SaveChanges();
// return RedirectToAction("Index");
//}
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = vendorUser.Email, Email = vendorUser.Email };
var result = UserManager.Create(user, "[email protected]");
var VendorUserId = db.AspNetUsers.Where(x => x.Email == vendorUser.Email).FirstOrDefault().Id;
string userAspId = VendorUserId;
vendorUser.AspId = userAspId;
string loginId = User.Identity.GetUserId();
int vendorId = db.Vendors.Where(x => x.AspId == loginId).FirstOrDefault().VendorId;
vendorUser.VendorId = vendorId;
db.VendorUsers.Add(vendorUser);
db.SaveChanges();
TempData["VendorId"] = vendorId;
return RedirectToAction("Index");
}
ViewBag.VendorId = new SelectList(db.Vendors, "VendorId", "Name", vendorUser.VendorId);
return View(vendorUser);
}
开发者ID:kashifshabih,项目名称:WebMart,代码行数:28,代码来源:VendorUsersController.cs
示例12: Index
public ActionResult Index()
{
//cria um usuário de sistema.
if (UserManager.FindByEmail("[email protected]") == null)
{
ApplicationUser systemUser = new ApplicationUser
{
UserName = "SPS",
Email = "[email protected]",
FirstName = "Smart Parking",
LastName = "System",
PhoneNumber = "(00) 00000-0000",
UserType = UserType.Client
};
var res = UserManager.Create(systemUser, "System12__");
if (res == null)
{
}
}
return View();
}
开发者ID:andremn,项目名称:SPS,代码行数:25,代码来源:HomeController.cs
示例13: CreateAccount
public ActionResult CreateAccount(NewUserModel model)
{
if (ModelState.IsValid)
{
ApplicationUserManager um = new ApplicationUserManager(new ApplicationUserStore(new ApplicationDbContext()));
var pass = StringHelper.RandomString(8, 10);
var user = new ApplicationUser()
{
Id = Guid.NewGuid().ToString(),
UserName = model.UserName,
Email = model.Email,
Created = DateTime.Now,
LastLogin = null
};
var result = um.Create(user, pass);
if(result.Succeeded)
{
MailHelper.WelcomeSendPassword(user.UserName, user.Email, pass);
return RedirectToAction("Index", "People");
}
else
{
foreach (var error in result.Errors)
{
ModelState.AddModelError("", error);
}
}
}
return View(model);
}
开发者ID:hurtonypeter,项目名称:onlab,代码行数:31,代码来源:PeopleController.cs
示例14: It_Sets_The_Basic_User_Information_For_The_Requested_User
public void It_Sets_The_Basic_User_Information_For_The_Requested_User()
{
expectedApplicationUser = new ApplicationUser
{
Id = "some application user id",
UserName = "some user name",
Email = "some email address",
UserGamingGroups = new List<UserGamingGroup>
{
new UserGamingGroup
{
GamingGroup = new GamingGroup()
}
},
Players = new List<Player>(),
BoardGameGeekUser = new BoardGameGeekUserDefinition
{
Name = "bgg name",
Id = 1
}
};
var userQueryable = new List<ApplicationUser>
{
expectedApplicationUser,
new ApplicationUser()
}.AsQueryable();
autoMocker.Get<IDataContext>().Expect(mock => mock.GetQueryable<ApplicationUser>()).Return(userQueryable);
var actualResult = autoMocker.ClassUnderTest.RetrieveUserInformation(expectedApplicationUser);
Assert.That(actualResult.UserId, Is.EqualTo(expectedApplicationUser.Id));
Assert.That(actualResult.UserName, Is.EqualTo(expectedApplicationUser.UserName));
Assert.That(actualResult.Email, Is.EqualTo(expectedApplicationUser.Email));
Assert.That(actualResult.BoardGameGeekUser.Name, Is.EqualTo(expectedApplicationUser.BoardGameGeekUser.Name));
}
开发者ID:NemeStats,项目名称:NemeStats,代码行数:35,代码来源:RetrieveUserInformationTests.cs
示例15: GetTrackInfo
public override UmcTrack GetTrackInfo(string url, ApplicationUser currentUser)
{
ISoundCloudConnector soundCloudConnector = new SoundCloudConnector();
string token = currentUser.ApplicationUserData.SoundcloudToken;
//string token = "ssadad";
UmcTrack resultTrack = new SoundcloudTrack();
//var tokenLogin = soundCloudConnector.RefreshToken(clientId, clientSecret, token);
//var newToken = tokenLogin.AccessToken;
//var soundCloudClient = soundCloudConnector.Connect(new SCAccessToken {AccessToken = token});
var soundCloudClient = soundCloudConnector.UnauthorizedConnect(clientId, clientSecret);
var track = soundCloudClient.Resolve.GetTrack(url);
resultTrack.Url = url;
resultTrack.Title = track.Title;
resultTrack.Artist = track.User.UserName;
resultTrack.Year = track.CreatedAt.Year.ToString();
resultTrack.InternalId = track.Id;
return resultTrack;
}
开发者ID:Loydik,项目名称:UniversalMusicPlayer,代码行数:25,代码来源:SoundcloudDataParser.cs
示例16: SetCreated
public EntityBase SetCreated(ApplicationUser user)
{
CreatedOn = DateTime.Now;
//CreatedBy = user;
UpdatedOn = DateTime.Now;
return this;
}
开发者ID:Capplequoppe,项目名称:CurlerOnline,代码行数:7,代码来源:EntityBase.cs
示例17: SetUp
public override void SetUp()
{
base.SetUp();
expectedGamingGroup = new GamingGroup() { Id = currentUser.CurrentGamingGroupId };
autoMocker.Get<IDataContext>().Expect(mock => mock.Save(Arg<GamingGroup>.Is.Anything, Arg<ApplicationUser>.Is.Anything))
.Return(expectedGamingGroup);
expectedPlayer = new Player();
autoMocker.Get<IPlayerSaver>().Expect(mock => mock.CreatePlayer(
Arg<CreatePlayerRequest>.Is.Anything,
Arg<ApplicationUser>.Is.Anything,
Arg<bool>.Is.Anything)).Return(expectedPlayer);
expectedUserGamingGroup = new UserGamingGroup
{
ApplicationUserId = currentUser.Id,
GamingGroupId = expectedGamingGroup.Id
};
autoMocker.Get<IDataContext>().Expect(mock => mock.Save<UserGamingGroup>(Arg<UserGamingGroup>.Is.Anything, Arg<ApplicationUser>.Is.Anything))
.Return(expectedUserGamingGroup);
appUserRetrievedFromFindMethod = new ApplicationUser()
{
Id = currentUser.Id
};
autoMocker.Get<IDataContext>().Expect(mock => mock.FindById<ApplicationUser>(Arg<ApplicationUser>.Is.Anything))
.Return(appUserRetrievedFromFindMethod);
autoMocker.Get<IDataContext>().Expect(mock => mock.Save(Arg<ApplicationUser>.Is.Anything, Arg<ApplicationUser>.Is.Anything))
.Return(new ApplicationUser());
}
开发者ID:NemeStats,项目名称:NemeStats,代码行数:30,代码来源:CreateNewGamingGroupTests.cs
示例18: Register
public async Task<ActionResult> Register(RegisterVm Model)
{
Tuple<RegisterVm, LoginVm> badModel;
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = Model.EmailReg, Email = Model.EmailReg };
IdentityUserClaim _claim = new Microsoft.AspNet.Identity.EntityFramework.IdentityUserClaim();
_claim.ClaimType = "FullName";
_claim.ClaimValue = Model.FullName;
_claim.UserId = user.Id;
user.Claims.Add(_claim);
ViewBag.FullName = Model.FullName;
ViewBag.Email = user.Email;
Random random = new Random(DateTime.Now.Day);
StringBuilder strBuilder = new StringBuilder("!164");
for (int i = 0; i < 3; i++)
{
strBuilder.Append((char)random.Next(65, 90));
strBuilder.Append((char)random.Next(97, 122));
}
string temporaryPassword = strBuilder.ToString();
var result = await UserManager.CreateAsync(user, temporaryPassword);
if (result.Succeeded)
{
await SignInManager.SignInAsync(user, isPersistent: false, rememberBrowser: false);
string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
var callbackUrl = Url.Action("ConfirmEmailAndChangePassword", "Init", new { userId = System.Web.HttpUtility.UrlEncode(user.Id), code = System.Web.HttpUtility.UrlEncode(code) }, protocol: Request.Url.Scheme);
try
{
ViewBag.Logo = Url.Content("~/Content/images/init/Logo.png", true);
ViewBag.ConfirmReference = callbackUrl;
string textmail = ViewToString("emailConfirmation", null);
await UserManager.SendEmailAsync(user.Id, "Confirm your account", textmail);//"Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");
}
catch (SmtpException e1)
{
await UserManager.DeleteAsync(user);
ViewBag.UnsuccessfulError = e1.Message;
ModelState.AddModelError("", "Не удалось создать пользователя. " + e1.Message);
badModel =
new Tuple<RegisterVm, LoginVm>(Model, new LoginVm());
return View("Welcome", badModel);
}
return View("RegisterConfirmationSent");
}
else
{
ModelState.AddModelError("", "Не удалось создать пользователя. " + result.Errors.First());
}
}
// If we got this far, something failed, redisplay form
badModel = new Tuple<RegisterVm, LoginVm>(Model, new LoginVm());
return View("Index", badModel);
}
开发者ID:AleksanderGalkin,项目名称:MyBlog,代码行数:60,代码来源:InitController.cs
示例19: AddUserAndRole
internal void AddUserAndRole()
{
// access the application context and create result variables.
Models.ApplicationDbContext context = new ApplicationDbContext();
IdentityResult IdRoleResult;
IdentityResult IdUserResult;
// create roleStore object that can only contain IdentityRole objects by using the ApplicationDbContext object.
var roleStore = new RoleStore<IdentityRole>(context);
var roleMgr = new RoleManager<IdentityRole>(roleStore);
// create admin role if it doesn't already exist
if (!roleMgr.RoleExists("admin"))
{
IdRoleResult = roleMgr.Create(new IdentityRole { Name = "admin" });
}
// create a UserManager object based on the UserStore object and the ApplicationDbContext object.
// defines admin email account
var userMgr = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(context));
var appUser = new ApplicationUser
{
UserName = "[email protected]",
Email = "[email protected]"
};
IdUserResult = userMgr.Create(appUser, "Pa$$word1");
// If the new admin user was successfully created, add the new user to the "admin" role.
if (!userMgr.IsInRole(userMgr.FindByEmail("[email protected]").Id, "admin"))
{
IdUserResult = userMgr.AddToRole(userMgr.FindByEmail("[email protected]").Id, "admin");
}
}
开发者ID:SCCapstone,项目名称:ZVerse,代码行数:33,代码来源:RoleActions.cs
示例20: Register
public async Task<ActionResult> Register(RegisterViewModel model)
{
if (ModelState.IsValid)
{
var user = new ApplicationUser { UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName};
try
{
var result = await UserManager.CreateAsync(user, model.Password);
if (result.Succeeded)
{
await SignInAsync(user, false);
return RedirectToAction("Index", "Home");
}
AddErrors(result);
}
catch (Exception)
{
//When no database, sometimes database creation fails.
AddErrors(new IdentityResult("Database creation failed, please restart the application!"));
return View(model);
}
}
// If we got this far, something failed, redisplay form
return View(model);
}
开发者ID:arkirakosyan,项目名称:MyStories,代码行数:27,代码来源:AccountController.cs
注:本文中的ApplicationUser类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论