Esempio n. 1
0
        public static void SeedUsers(UserManager <PageUser> userManager)
        {
            if (userManager.FindByNameAsync("normaluser").Result == null)
            {
                PageUser user = new PageUser();
                user.UserName = "******";
                user.Email    = "[email protected]";

                IdentityResult result = userManager.CreateAsync
                                            (user, "P@ssw0rd").Result;

                if (result.Succeeded)
                {
                    userManager.AddToRoleAsync(user, "NormalUser").Wait();
                }
            }

            if (userManager.FindByNameAsync("admin").Result == null)
            {
                PageUser user = new PageUser();
                user.UserName = "******";
                user.Email    = "*****@*****.**";

                IdentityResult result = userManager.CreateAsync
                                            (user, "P@ssw0rd").Result;

                if (result.Succeeded)
                {
                    userManager.AddToRoleAsync(user, "Administrator").Wait();
                }
            }
        }
Esempio n. 2
0
        /// Действие на нажатие на кнопку Войти
        private void btn_enter_Click(object sender, RoutedEventArgs e)
        {
            Settings.User.Default.login = tb_login.Text;
            Settings.User.Default.Save();

            try
            {
                using RegistrantCoreContext ef = new RegistrantCoreContext();
                var user = ef.Users.FirstOrDefault(x => tb_login.Text == x.Login && tb_password.Password == x.Password);

                if (user != null)
                {
                    ContentAuth.Hide();
                    App.SetActiveUser(user.Name);
                    App.SetLevelAccess(user.LevelAccess);
                    NavUI.PaneTitle     = "РЕГИСТРАНТ (" + user.Name + ")";
                    nav_userset.Content = user.Name;
                    _pageUser           = new PageUser(user.IdUser);

                    Thread thread = new Thread(Verify);
                    thread.Start();
                }
                else
                {
                    MessageBox.Show("Логин и/или пароль неверный", "Ошибка входа", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
            catch (Exception ex)
            {
                Dispatcher.Invoke(() => ContentWait.Hide());
                Dispatcher.Invoke(() => ContentError.ShowAsync());
                Dispatcher.Invoke(() => text_error.Text = ex.ToString());
            }
        }
Esempio n. 3
0
        private void Setting_CheckedChanged(object sender, EventArgs e)
        {
            RadioButton rbtn = sender as RadioButton;

            if (rbtn.Checked == true)
            {
                if (m_LastSettingPage != null)
                {
                    this.tlpSettingBase.Controls.RemoveAt(2);
                    m_LastSettingPage.Dispose();
                    m_LastSettingPage = null;
                }

                switch (rbtn.Name)
                {
                case string rbtnName when rbtnMachine.Name == rbtnName:
                    PageMachine pMachine = new PageMachine();
                    pMachine.Setup();
                    m_LastSettingPage = pMachine;
                    break;

                case string rbtnName when rbtnCar.Name == rbtnName:
                    PageCars pCars = new PageCars();
                    pCars.Setup();
                    m_LastSettingPage = pCars;
                    break;

                case string rbtnName when rbtnUser.Name == rbtnName:
                    PageUser pUser = new PageUser();
                    pUser.Setup();
                    m_LastSettingPage = pUser;
                    break;

                case string rbtnName when rbtnBackup.Name == rbtnName:
                    PageBackup pBackup = new PageBackup();
                    pBackup.Setup();
                    m_LastSettingPage = pBackup;
                    break;

                case string rbtnName when rbtnReport.Name == rbtnName:
                    PageReport pReport = new PageReport(m_Machine);
                    pReport.Setup();
                    m_LastSettingPage = pReport;
                    break;

                case string rbtnName when rbtnPrinter.Name == rbtnName:
                    PagePrinterSetting pPrinter = new PagePrinterSetting();
                    pPrinter.Setup();
                    m_LastSettingPage = pPrinter;
                    break;
                }

                tlpSettingBase.Controls.Add(m_LastSettingPage, 2, 0);
                m_LastSettingPage.Dock = DockStyle.Fill;
            }
        }
Esempio n. 4
0
        public async Task <Page> CreatePage(Company company, User user)
        {
            var page = new Page(company, user);

            await _pageRepository.Add(page);

            var newPageOwner = new PageUser(page, user);

            await _pageOwnerRepository.Add(newPageOwner);

            return(await _pageRepository.GetById(page.Id));
        }
Esempio n. 5
0
        public async Task <UserStatsVM> GetUserStats(PageUser user)
        {
            UserStatsVM stats = new UserStatsVM()
            {
                UserId        = user.Id,
                UserName      = user.UserName,
                UserRole      = _userManager.GetRolesAsync(user).Result.FirstOrDefault(),
                TotalMemes    = await _memeService.CountAsync(m => m.PageUser.UserName == user.UserName),
                TotalAccepted = await _memeService.CountAsync(m => m.PageUser.UserName == user.UserName && m.IsAccepted),
                TotalComments = await _commentService.CountAsync(m => m.PageUser.UserName == user.UserName),
                Joined        = user.CreationDate.ToString("dd/MM/yyyy"),
            };

            return(stats);
        }
Esempio n. 6
0
        public async Task <ListedUserVM> MapListedUserVM(PageUser user)
        {
            var role = await _userManager.GetRolesAsync(user);

            ListedUserVM vm = new ListedUserVM();

            vm.UserId       = user.Id;
            vm.UserName     = user.UserName;
            vm.Email        = user.Email;
            vm.CreationDate = user.CreationDate.ToString("dd/MM/yyyy hh:mm");
            vm.MemeCount    = await _memeService.CountAsync(m => m.UserID == user.Id);

            vm.CommentCount = await _commentService.CountAsync(m => m.UserID == user.Id);

            vm.UserRole = role.FirstOrDefault();
            return(vm);
        }
Esempio n. 7
0
        public async Task <IdentityResult> RegisterUser(RegisterVM model)
        {
            var user = new PageUser {
                UserName = model.UserName, Email = model.Email, CreationDate = DateTime.Now
            };

            try
            {
                var result = await _userManager.CreateAsync(user, model.Password);

                await _userManager.AddToRoleAsync(user, "NormalUser");

                return(result);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 8
0
        public async Task <IdentityResult> SetRole(PageUser user, string removeFrom, string addTo)
        {
            await _userManager.RemoveFromRoleAsync(user, removeFrom);

            return(await _userManager.AddToRoleAsync(user, addTo));
        }