public async Task <IActionResult> Register(RegisterViewModel _model, string _returnUrl = null)
        {
            ViewData["ReturnUrl"] = _returnUrl;
            if (ModelState.IsValid)
            {
                var _user = new IdentityDBContext {
                    UserName = _model.Email, Email = _model.Email
                };
                var _result = await _userManager.CreateAsync(_user, _model.Password);

                if (_result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    var _code = await _userManager.GenerateEmailConfirmationTokenAsync(_user);

                    //var _callbackUrl = Url.EmailConfirmationLink(_user.Id, _code, Request.Scheme);
                    //await _emailSender.SendEmailAsync(_model.Email, _callbackUrl);
                    await _signInManager.SignInAsync(_user, isPersistent : false);

                    _logger.LogInformation("User created a new account with password.");
                    return(RedirectToLocal(_returnUrl));
                }
                AddErrors(_result);
            }
            return(View(_model));
        }
示例#2
0
文件: Menu.cs 项目: xthjan/transprt
        public static void AssignMenuToModel(Menu menu)
        {
            IdentityDBContext     db          = new IdentityDBContext();
            RoleManager <AppRole> RoleManager = new RoleManager <AppRole>(new RoleStore <AppRole>(db));
            var activeRoles  = RoleManager.Roles.Where(rol => rol.activo);
            var menusCreados = activeRoles.Select(rol => new MenuByArea()
            {
                id_area = rol.Id,
                Nombre  = rol.Name
            }).ToList();

            if (menu.id != 0)
            {
                menusCreados = activeRoles.Select(rol => new MenuByArea()
                {
                    id_area = rol.Id,
                    Nombre  = rol.Name,
                    id_menu = menu.id
                }).ToList();
                menusCreados.ForEach(menuAreaCreado => {
                    menuAreaCreado.Asignado = menu.MenuByAreas.Any(menuArea => menuArea.id_area == menuAreaCreado.id_area);
                });
            }
            menu.MenuByAreas = menusCreados;
        }
示例#3
0
        public void ConfigureRoles()
        {
            using (IdentityDBContext context = new IdentityDBContext()) {
                var roleManager = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));
                var UserManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(context));

                // Admin role
                if (!roleManager.RoleExists("Manager"))
                {
                    // Create admin role
                    roleManager.Create(new IdentityRole("Manager"));

                    // Create admin account
                    var user = new ApplicationUser {
                        UserName = "******",
                        Email    = "*****@*****.**",
                    };
                    string password = "******";

                    var createUserTransaction = UserManager.Create(user, password);
                    if (createUserTransaction.Succeeded)
                    {
                        UserManager.AddToRole(user.Id, "Manager");
                    }
                }

                // Mortals role
                if (!roleManager.RoleExists("Employee"))
                {
                    roleManager.Create(new IdentityRole("Employee"));
                }
            }
        }
示例#4
0
        public static IEnumerable <ApiResource> GetApiResource(String Connectionstring)
        {
            IdentityDBContext  _db          = new IdentityDBContext(new DbContextOptionsBuilder <IdentityDBContext>().UseSqlServer(Connectionstring).Options);
            List <ApiResource> apiresources = new List <ApiResource>();

            foreach (IdentityServer.Models.Application app in _db.Applications.ToList())
            {
                apiresources.Add(new ApiResource(app.Name, app.Name));
            }
            return(apiresources);
        }
        // GET: Account
        public AccountController()
        {
            IdentityDBContext DB = new IdentityDBContext();

            UserStore <ApplicationUser> userStore = new UserStore <ApplicationUser>(DB);

            userManager = new UserManager <ApplicationUser>(userStore);                  //manager'ı hangi store üzerinde barındırmak istiyorsun diye soruyor veriyorum barındırmak istediğim yeri
            RoleStore <ApplicationRole> roleStore = new RoleStore <ApplicationRole>(DB); //Gene bu manager'ı hangi store üzerinde barındırmak istediğimi soruyor.

            roleManager = new RoleManager <ApplicationRole>(roleStore);                  //rolStore'dan türettim
        }
示例#6
0
        public async Task <IEnumerable <UserOwnership> > GetUserOwnershipAsync(string UserID)
        {
            using (var _context = new IdentityDBContext(_dbOptions))
            {
                var task = await _context.UserOwnership.Where(u => u.UserId.Equals(UserID, StringComparison.InvariantCultureIgnoreCase)).AsNoTracking().ToListAsync();

                if (task == null || !task.Any())
                {
                    return(null);
                }
                return(task);
            }
        }
示例#7
0
        public async Task <UserOwnership> GetUserOwnershipAsync(UserOwnership userOwnership)
        {
            using (var _context = new IdentityDBContext(_dbOptions))
            {
                var task = await _context.UserOwnership.FindAsync(userOwnership.UserId, userOwnership.ConferenceId);

                if (task == null)
                {
                    return(null);
                }

                return(task);
            }
        }
示例#8
0
        public async Task <UserAgenda> GetUserAgendaAsync(UserAgenda userAgenda)
        {
            using (var _context = new IdentityDBContext(_dbOptions))
            {
                var task = await _context.UserAgenda.FindAsync(userAgenda.UserId, userAgenda.ConferenceId, userAgenda.SessionId, userAgenda.TalkId);

                if (task == null)
                {
                    return(null);
                }

                return(task);
            }
        }
示例#9
0
        public async Task <UserOwnership> AddUserOwnershipAsync(UserOwnership userOwnership)
        {
            using (var _context = new IdentityDBContext(_dbOptions))
            {
                var exists = GetUserOwnershipAsync(userOwnership).Result;
                if (exists != null)
                {
                    return(exists);
                }

                _context.UserOwnership.Add(userOwnership);
                await _context.SaveChangesAsync();

                return(GetUserOwnershipAsync(userOwnership).Result);
            }
        }
示例#10
0
        public async Task <UserAgenda> DeleteUserAgenda(string userId, int conferenceId, int sessionId, int talkId)
        {
            using (var _context = new IdentityDBContext(_dbOptions))
            {
                var task = await _context.UserAgenda.FindAsync(userId, conferenceId, sessionId, talkId);

                if (task == null)
                {
                    return(null);
                }

                _context.UserAgenda.Remove(task);
                await _context.SaveChangesAsync();

                return(task);
            }
        }
示例#11
0
        public async Task <UserOwnership> DeleteUserOwnership(string userId, int conferenceId)
        {
            using (var _context = new IdentityDBContext(_dbOptions))
            {
                var task = await _context.UserOwnership.FindAsync(userId, conferenceId);

                if (task == null)
                {
                    return(null);
                }

                _context.UserOwnership.Remove(task);
                await _context.SaveChangesAsync();

                return(task);
            }
        }
示例#12
0
        //Global.asax applicationsal işlemlerimi yapar.
        protected void Application_Start()
        {
            AreaRegistration.RegisterAllAreas();
            RouteConfig.RegisterRoutes(RouteTable.Routes);
            IdentityDBContext             DB       = new IdentityDBContext();
            RoleStore <ApplicationRole>   rStore   = new RoleStore <ApplicationRole>(DB);
            RoleManager <ApplicationRole> rManager = new RoleManager <ApplicationRole>(rStore);

            if (!rManager.RoleExists("Admin"))
            {
                ApplicationRole adminRole = new ApplicationRole("Admin", "SistemYöneticisi");
                rManager.Create(adminRole);
            }
            if (!rManager.RoleExists("User"))
            {
                ApplicationRole userRole = new ApplicationRole("User", "SistemKullanici");
                rManager.Create(userRole);
            }
        }
示例#13
0
        public static IEnumerable <IdentityServer4.Models.Client> GetClients(String Connectionstring)
        {
            IdentityDBContext _db = new IdentityDBContext(new DbContextOptionsBuilder <IdentityDBContext>().UseLazyLoadingProxies().UseSqlServer(Connectionstring).Options);
            List <IdentityServer4.Models.Client> clientes = new List <IdentityServer4.Models.Client>();

            foreach (IdentityServer.Models.Client cli in _db.Clients.ToList())
            {
                IdentityServer4.Models.Client icli = new IdentityServer4.Models.Client();
                icli.ClientId          = cli.UserName;
                icli.AllowedGrantTypes = GrantTypes.ClientCredentials;
                icli.ClientSecrets.Add(new Secret(cli.Password.Sha256()));
                foreach (Scope scope in _db.Scopes.ToList())
                {
                    if (scope.ClientId == cli.ClientId)
                    {
                        icli.AllowedScopes.Add(scope.ApplicationId.ToString());
                    }
                }
                clientes.Add(icli);
            }
            return(clientes);
        }
示例#14
0
 public ScopesController(IdentityDBContext context)
 {
     _context = context;
 }
示例#15
0
 public DataAdapter(IdentityDBContext identityDbContext)
 {
     this.identityDbContext = identityDbContext;
 }
示例#16
0
 public ToDoController(IdentityDBContext identityDBContext)
 {
     _identityDBContext = identityDBContext;
 }
示例#17
0
 public HomeController(IdentityDBContext identityDBContext)
 {
     _identityDBContext = identityDBContext;
 }
示例#18
0
 public ApplicationUserStore(IdentityDBContext context)
     : base(context)
 {
 }
示例#19
0
 public IdentityController(IdentityDBContext dbcontext, IConfiguration config)
 {
     db            = dbcontext;
     configuration = config;
 }
示例#20
0
 public RegisterUserCommandHandler(IdentityDBContext dbContext)
 {
     _dbContext = dbContext;
 }
示例#21
0
 public EmailSender(IdentityDBContext idContext, IOptions <EmailConfig> emailConfig)
 {
     _idContext   = idContext;
     _emailConfig = emailConfig?.Value;
 }
示例#22
0
 protected BaseService(IContextProvider contextProvider, ILoggerFactory loggerFactory, IdentityDBContext context)
     : base(loggerFactory)
 {
     _session = contextProvider.GetCurrentContext();
     _context = context;
 }
示例#23
0
 public HomeController(IdentityDBContext dbContext)
 {
     _dbContext = dbContext;
 }
示例#24
0
 public RegisterUserCommandHandler(IdentityDBContext dbContext, IKafkaMessageBus <string, User> bus)
 {
     _bus       = bus;
     _dbContext = dbContext;
 }
 public CustomerUpdatedEventHandler(IdentityDBContext dbContext)
 {
     _dbContext = dbContext;
 }
示例#26
0
 public IdentityRepository(IdentityDBContext context, IMapper mapper) : base(context, mapper)
 {
     this.context = context;
     this.mapper  = mapper;
 }
示例#27
0
 public SettingsService(IContextProvider contextProvider, ILoggerFactory loggerFactory, IdentityDBContext context)
     : base(contextProvider, loggerFactory, context)
 {
 }
示例#28
0
 public AuthService(IdentityDBContext context, IConfiguration configuration)
 {
     _configuration = configuration;
     _context       = context;
 }
示例#29
0
 public ApplicationsController(IdentityDBContext context)
 {
     _context = context;
 }
 public IdentityController(IdentityDBContext dbContext, IConfiguration configuration)
 {
     db     = dbContext;
     config = configuration;
 }