Advertisement
Guest User

Untitled

a guest
Feb 20th, 2016
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.48 KB | None | 0 0
  1. $scope.register = function () {
  2. if (!$scope.register.email || !$scope.register.password || !$scope.register.confirmPassword) {
  3. return;
  4. }
  5. var config = {
  6. headers: {
  7. 'Content-Type': 'application/json; charset=utf-8'
  8. }
  9. };
  10.  
  11. var data = {
  12. Email: $scope.register.email,
  13. Password: $scope.register.password,
  14. confirmPassword: $scope.register.confirmPassword
  15. }
  16.  
  17.  
  18. $http.post('/api/Account/Register', JSON.stringify(data), config).
  19. success(function (data) {
  20. $location.path('/#admin')
  21. }).
  22. error(function () {
  23. return
  24. });
  25. };
  26.  
  27. // POST api/Account/Register
  28. [AllowAnonymous]
  29. [Route("Register")]
  30. public async Task<IHttpActionResult> Register(RegisterBindingModel model)
  31. {
  32. if (!ModelState.IsValid)
  33. {
  34. return BadRequest(ModelState);
  35. }
  36.  
  37. try {
  38. var user = new ApplicationUser() { UserName = model.Email, Email = model.Email };
  39.  
  40. IdentityResult result = await UserManager.CreateAsync(user, model.Password);
  41.  
  42. if (!result.Succeeded)
  43. {
  44. return GetErrorResult(result);
  45. }
  46.  
  47. return Ok();
  48. }
  49. catch(Exception ex)
  50. {
  51. throw; //Yes I know this is not correctly handling the error
  52. }
  53. }
  54.  
  55. public ApplicationUserManager UserManager
  56. {
  57. get
  58. {
  59. return _userManager ?? Request.GetOwinContext().GetUserManager<ApplicationUserManager>();
  60. }
  61. private set
  62. {
  63. _userManager = value;
  64. }
  65. }
  66.  
  67. public class ApplicationUserManager : UserManager<ApplicationUser>
  68. {
  69. public ApplicationUserManager(IUserStore<ApplicationUser> store)
  70. : base(store)
  71. {
  72. }
  73.  
  74. public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
  75. {
  76. var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<DaumAuctionEntities>()));
  77. var dataProtectionProvider = options.DataProtectionProvider;
  78.  
  79. // Configure validation logic for usernames
  80. manager.UserValidator = new UserValidator<ApplicationUser>(manager)
  81. {
  82. AllowOnlyAlphanumericUserNames = false,
  83. RequireUniqueEmail = true
  84. };
  85.  
  86. // Configure validation logic for passwords
  87. manager.PasswordValidator = new PasswordValidator
  88. {
  89. RequiredLength = 6,
  90. RequireNonLetterOrDigit = false,
  91. RequireDigit = false,
  92. RequireLowercase = true,
  93. RequireUppercase = true,
  94. };
  95.  
  96. if (dataProtectionProvider != null)
  97. {
  98. manager.UserTokenProvider = new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
  99. }
  100.  
  101. return manager;
  102. }
  103. }
  104.  
  105. public class ApplicationUser : IdentityUser
  106. {
  107. public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType)
  108. {
  109. // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType
  110. var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
  111. // Add custom user claims here
  112. return userIdentity;
  113. }
  114. }
  115.  
  116. public partial class DaumAuctionEntities : IdentityDbContext<ApplicationUser>
  117. {
  118. public DaumAuctionEntities()
  119. : base("name=DaumAuctionEntities")
  120. {
  121. }
  122.  
  123. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  124. {
  125. throw new UnintentionalCodeFirstException();
  126. }
  127.  
  128. public static DaumAuctionEntities Create()
  129. {
  130. return new DaumAuctionEntities();
  131. }
  132.  
  133. public DbSet<addresses> addresses { get; set; }
  134. public DbSet<auctions> auctions { get; set; }
  135. public DbSet<images> images { get; set; }
  136. public DbSet<users> users { get; set; }
  137. public DbSet<labels> labels { get; set; }
  138. }
  139.  
  140. public partial class DaumAuctionEntities : DbContext
  141. {
  142. public DaumAuctionEntities()
  143. : base("name=DaumAuctionEntities")
  144. {
  145. }
  146.  
  147. protected override void OnModelCreating(DbModelBuilder modelBuilder)
  148. {
  149. throw new UnintentionalCodeFirstException();
  150. }
  151.  
  152. public DbSet<addresses> addresses { get; set; }
  153. public DbSet<auctions> auctions { get; set; }
  154. public DbSet<images> images { get; set; }
  155. public DbSet<users> users { get; set; }
  156. public DbSet<labels> labels { get; set; }
  157. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement