Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $scope.register = function () {
- if (!$scope.register.email || !$scope.register.password || !$scope.register.confirmPassword) {
- return;
- }
- var config = {
- headers: {
- 'Content-Type': 'application/json; charset=utf-8'
- }
- };
- var data = {
- Email: $scope.register.email,
- Password: $scope.register.password,
- confirmPassword: $scope.register.confirmPassword
- }
- $http.post('/api/Account/Register', JSON.stringify(data), config).
- success(function (data) {
- $location.path('/#admin')
- }).
- error(function () {
- return
- });
- };
- // POST api/Account/Register
- [AllowAnonymous]
- [Route("Register")]
- public async Task<IHttpActionResult> Register(RegisterBindingModel model)
- {
- if (!ModelState.IsValid)
- {
- return BadRequest(ModelState);
- }
- try {
- var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
- IdentityResult result = await UserManager.CreateAsync(user, model.Password);
- if (!result.Succeeded)
- {
- return GetErrorResult(result);
- }
- return Ok();
- }
- catch(Exception ex)
- {
- throw; //Yes I know this is not correctly handling the error
- }
- }
- public ApplicationUserManager UserManager
- {
- get
- {
- return _userManager ?? Request.GetOwinContext().GetUserManager<ApplicationUserManager>();
- }
- private set
- {
- _userManager = value;
- }
- }
- public class ApplicationUserManager : UserManager<ApplicationUser>
- {
- public ApplicationUserManager(IUserStore<ApplicationUser> store)
- : base(store)
- {
- }
- public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
- {
- var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<DaumAuctionEntities>()));
- var dataProtectionProvider = options.DataProtectionProvider;
- // Configure validation logic for usernames
- manager.UserValidator = new UserValidator<ApplicationUser>(manager)
- {
- AllowOnlyAlphanumericUserNames = false,
- RequireUniqueEmail = true
- };
- // Configure validation logic for passwords
- manager.PasswordValidator = new PasswordValidator
- {
- RequiredLength = 6,
- RequireNonLetterOrDigit = false,
- RequireDigit = false,
- RequireLowercase = true,
- RequireUppercase = true,
- };
- if (dataProtectionProvider != null)
- {
- manager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
- }
- return manager;
- }
- }
- public class ApplicationUser : IdentityUser
- {
- public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType)
- {
- // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
- var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
- // Add custom user claims here
- return userIdentity;
- }
- }
- public partial class DaumAuctionEntities : IdentityDbContext<ApplicationUser>
- {
- public DaumAuctionEntities()
- : base("name=DaumAuctionEntities")
- {
- }
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- throw new UnintentionalCodeFirstException();
- }
- public static DaumAuctionEntities Create()
- {
- return new DaumAuctionEntities();
- }
- public DbSet<addresses> addresses { get; set; }
- public DbSet<auctions> auctions { get; set; }
- public DbSet<images> images { get; set; }
- public DbSet<users> users { get; set; }
- public DbSet<labels> labels { get; set; }
- }
- public partial class DaumAuctionEntities : DbContext
- {
- public DaumAuctionEntities()
- : base("name=DaumAuctionEntities")
- {
- }
- protected override void OnModelCreating(DbModelBuilder modelBuilder)
- {
- throw new UnintentionalCodeFirstException();
- }
- public DbSet<addresses> addresses { get; set; }
- public DbSet<auctions> auctions { get; set; }
- public DbSet<images> images { get; set; }
- public DbSet<users> users { get; set; }
- public DbSet<labels> labels { get; set; }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement