public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager, string authenticationType)
 {
     // Обратите внимание, что authenticationType должен совпадать с типом, определенным в CookieAuthenticationOptions.AuthenticationType
     var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);
     // Здесь добавьте настраиваемые утверждения пользователя
     return userIdentity;
 }
コード例 #2
0
        public ActionResult Create(IdeaPostViewModel idea)
        {
            var userManager = new UserManager<User>(new UserStore<User>(new UserVoiceSystemDbContext()));
            var newIdea = new Idea()
            {
                Title = new HtmlSanitizer().Sanitize(idea.Title),
                Description = new HtmlSanitizer().Sanitize(idea.Description)
            };

            var userId = this.User.Identity.GetUserId();
            if (userId != null)
            {
                var user = userManager.FindById(userId);
                newIdea.AuthorIpAddress = user.IpAddress;
            }
            else
            {
                newIdea.AuthorIpAddress = this.GetRandomIpAddress();
            }

            this.ideas.Add(newIdea);
            this.ideas.SaveChanges();

            return this.RedirectToAction("Index", "Home");
        }
 protected void MakeAdminButton_Click(object sender, EventArgs e)
 {
     string userId = this.Request.QueryString["UserId"];
     var userStore = new UserStore<User>(new TheCodeBookProjectDbContext());
     var userManager = new UserManager<User>(userStore);
     userManager.AddToRole(userId, "admin");
     this.Response.Redirect("~/Admin/Users.aspx");
 }
コード例 #4
0
 public UsersAdministrationController(
     ITownsService towns,
     UserManager<ApplicationUser> manager,
     IAdvertisementsService advertisements,
     ICommentsService comments,
     IMessagesService messages)
 {
     this.towns = towns;
     this.manager = manager;
     this.messages = messages;
     this.advertisements = advertisements;
     this.comments = comments;
 }
コード例 #5
0
        public void SeedUsers(AuctionDbContext context)
        {
            var store = new UserStore<User>(context);
            var manager = new UserManager<User>(store);

            User admin = new User
            {
                UserName = "******",
                Email = "*****@*****.**",
                FirstName = "Tosho",
                LastName = "Ivanov",
                PhoneNumber = "+3591234569",
                SecurityStamp = Guid.NewGuid().ToString(),
                PasswordHash = this.hasher.HashPassword("1"),
            };

            User pesho = new User
            {
                UserName = "******",
                Email = "*****@*****.**",
                FirstName = "Pesho",
                LastName = "Goshov",
                PhoneNumber = "+3591234567",
                SecurityStamp = Guid.NewGuid().ToString(),
                PasswordHash = this.hasher.HashPassword("1"),
            };

            User gosho = new User
            {
                UserName = "******",
                Email = "*****@*****.**",
                FirstName = "Gosho",
                LastName = "Toshov",
                PhoneNumber = "+3591234568",
                SecurityStamp = Guid.NewGuid().ToString(),
                PasswordHash = this.hasher.HashPassword("1"),
            };

            this.Users.Add(pesho);
            this.Users.Add(gosho);
            this.Users.Add(admin);
            context.Users.AddOrUpdate(this.Users.ToArray());
            context.SaveChanges();

            var adminId = context.Users.FirstOrDefault(u => u.UserName == "*****@*****.**").Id;
            manager.AddToRole(adminId, "Admin");
            context.SaveChanges();
        }
コード例 #6
0
        public ActionResult Delete(int id)
        {
            var idea = this.ideas.GetById(id);
            var userManager = new UserManager<User>(new UserStore<User>(new UserVoiceSystemDbContext()));
            var userId = this.User.Identity.GetUserId();
            var user = userManager.FindById(userId);

            if (user.IpAddress != idea.AuthorIpAddress)
            {
                return this.RedirectToAction("Error", "Home");
            }

            this.ideas.Delete(idea);
            this.ideas.SaveChanges();
            return this.RedirectToAction("Index", "Home");
        }
コード例 #7
0
ファイル: AccountController.cs プロジェクト: gitsnet/AutoBid
        //public AccountController()
        //    : this(new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ObjectContext())))
        //{


        //}

        public AccountController(ICountryService countryService,
            UserManager<ApplicationUser> userManager,
             RoleManager<IdentityRole> roleManager,
             ICarSellerTypeService carSellerTypeService,
            IAspNetUsersAdditionalInfoService aspNetUsersAdditionalInfoService,
            ISellerPersonalInfoService sellerPersonalInfoService,
            ICompanyTypeService companyTypeService,
            ISellerCompanyInfoService sellerCompanyInfoService,
            ISellerCompanyLogoService sellerCompanyLogoService
            )
        {

            UserManager = userManager;
            RoleManager = roleManager;
            _countryService = countryService;
            _carSellerTypeService = carSellerTypeService;
            _aspNetUsersAdditionalInfoService = aspNetUsersAdditionalInfoService;
            _sellerPersonalInfoService = sellerPersonalInfoService;
            _companyTypeService = companyTypeService;
            _sellerCompanyInfoService = sellerCompanyInfoService;
            _sellerCompanyLogoService = sellerCompanyLogoService;
        }
コード例 #8
0
        public ActionResult AppUsers_Create([DataSourceRequest]DataSourceRequest request, AppUserGridViewModel appUser)
        {
            var userManager = new UserManager<AppUser>(new UserStore<AppUser>(this.context));
            var roleManager = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(this.context));

            if (!roleManager.Roles.Any())
            {
                roleManager.Create(new IdentityRole { Name = "User" });
                roleManager.Create(new IdentityRole { Name = "Admin" });
            }

            var newId = string.Empty;
            if (this.ModelState.IsValid)
            {
                AppUser userToCreate = new AppUser
                {
                    Avatar = appUser.Avatar,
                    Email = appUser.Email,
                    UserName = appUser.UserName,
                    FirstName = appUser.FirstName,
                    LastName = appUser.LastName
                };

                userManager.Create(userToCreate, appUser.Password);
                userManager.AddToRole(userToCreate.Id, "User");
                newId = userToCreate.Id;
            }

            var userToDisplay =
             this.users.All()
             .To<AppUserGridViewModel>()
             .FirstOrDefault(x => x.Id == newId);

            return this.Json(new[]
            {
                userToDisplay
            }.ToDataSourceResult(request, this.ModelState));
        }
コード例 #9
0
 public UsersController(IUsersService users)
 {
     this.users = users;
     this.userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
 }
コード例 #10
0
ファイル: User.cs プロジェクト: AndrewMitev/Baudi
        public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<User> manager, string authenticationType)
        {
            var userIdentity = await manager.CreateIdentityAsync(this, authenticationType);

            return userIdentity;
        }
コード例 #11
0
 public UserService(IRepository<User> users)
 {
     this.users = users;
     this.userManager = new UserManager<User>(new UserStore<User>(new RouteExtremeDbContext()));
 }
コード例 #12
0
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (_userManager != null)
                {
                    _userManager.Dispose();
                    _userManager = null;
                }

                if (_signInManager != null)
                {
                    _signInManager.Dispose();
                    _signInManager = null;
                }
            }

            base.Dispose(disposing);
        }
コード例 #13
0
 public AccountController(IContestsData data, UserManager userManager, ApplicationSignInManager signInManager)
     : base(data)
 {
     this.SignInManager = signInManager;
     this.UserManager = userManager;
 }
コード例 #14
0
 public AccountController(UserManager<User> userManager)
 {
     UserManager = userManager;
 }
コード例 #15
0
        private UserManager<User> GetManager()
        {
            var userStore = new UserStore<User>(this.context as MilitarySystemContext);
            var userManager = new UserManager<User>(userStore);
            userManager.UserValidator = new UserValidator<User>(userManager)
            {
                AllowOnlyAlphanumericUserNames = false,
                RequireUniqueEmail = true
            };

            // Configure validation logic for passwords
            userManager.PasswordValidator = new PasswordValidator
            {
                RequiredLength = 6,
                RequireNonLetterOrDigit = false,
                RequireDigit = false,
                RequireLowercase = false,
                RequireUppercase = false,
            };

            // Configure user lockout defaults
            userManager.UserLockoutEnabledByDefault = true;
            userManager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
            userManager.MaxFailedAccessAttemptsBeforeLockout = 5;

            return userManager;
        }
コード例 #16
0
        public ActionResult ResetPin(string card_id)
        {
            var UserManager = new UserManager<ApplicationUser>
                (
                new UserStore<ApplicationUser>("CoreDB_Server")
                );
            string newPassword = DateTime.Now.ToString("ssHHmm");
            if (!String.IsNullOrEmpty(Helper.DEFAULT_PIN)) newPassword = Helper.DEFAULT_PIN;
            dynamic current_user = Helper.DataHelper.Get("users", Query.EQ("UserName", card_id));
            Helper.DataHelper.Delete("users", current_user._id);
            var new_user = new ApplicationUser() { UserName = card_id, };
            var result = UserManager.Create(new_user, newPassword);
            if (result.Succeeded)
            {
                //add Roles to User
                string[] roles = new string[] { "CUSTOMER" };
                var roleResult = UserManager.AddToRole(new_user.Id, roles[0]);
                dynamic current_profile = Helper.DataHelper.Get("profile", Query.EQ("user_name", card_id));
                //CMSDBDataContext db = new CMSDBDataContext();
                //var card = (from element in db.Cards where element.CardId.Equals(card_id) select element).SingleOrDefault();
                //if (card != null)
                //{
                //    card.IsActived = false;
                //    db.SubmitChanges();
                //    db.Dispose();
                //}
                if (current_profile != null)
                {
                    current_profile.Pin = 1;
                    Helper.DataHelper.Save("profile", current_profile);
                }
            }
            //string token = UserManager.GenerateUserToken("ResetPassword", card_id);

            //bool succeded = UserManager.ResetPassword(card_id, token, newPassword).Succeeded;
            ViewBag.Result = "thành công. Mã PIN mới là " + newPassword;
            return View();
        }
コード例 #17
0
 protected override void Dispose(bool disposing)
 {
     if (disposing && UserManager != null)
     {
         UserManager.Dispose();
         UserManager = null;
     }
     base.Dispose(disposing);
 }
コード例 #18
0
        // Bindings for Identity, requires improvment.
        private static void RegisterIdentity(IKernel kernel)
        {
            kernel.Bind<IUserStore<User>>().To<AppUserStore>();

            kernel.Bind<UserManager<User>>().ToMethod<UserManager<User>>(ctx =>
            {
                var userStore = ctx.Kernel.Get<IUserStore<User>>();
                var manager = new UserManager<User>(userStore);

                var userValidator = new UserValidator<User>(manager);
                manager.UserValidator = IdentityConfig.Configure(userValidator);

                var passwordValidator = ctx.Kernel.Get<PasswordValidator>();
                manager.PasswordValidator = IdentityConfig.Configure(passwordValidator);

                IdentityConfig.Configure(manager);

                var phoneNumberTokenProvider = ctx.Kernel.Get<PhoneNumberTokenProvider<User>>();
                manager.RegisterTwoFactorProvider("Phone Code", IdentityConfig.Configure(phoneNumberTokenProvider));

                var emailTokenProvider = ctx.Kernel.Get<EmailTokenProvider<User>>();
                manager.RegisterTwoFactorProvider("Email Code", IdentityConfig.Configure(emailTokenProvider));

                var dataProtectionProvider = OwinConfig.DataProtectionProvider;

                if (dataProtectionProvider != null)
                {
                    manager.UserTokenProvider = new DataProtectorTokenProvider<User>(dataProtectionProvider.Create("ASP.NET Identity"));
                }

                return manager;
            });

            kernel.Bind<IAuthenticationManager>()
                .ToMethod(ctx => HttpContext.Current.GetOwinContext().Authentication)
                .InRequestScope();
        }
コード例 #19
0
 public AccountController(UserManager<ApplicationUser> userManager)
 {
     UserManager = userManager;
 }