コード例 #1
0
ファイル: DBUsers.cs プロジェクト: Rubell1on/DormitoryIS
        public static List <ISUser> GetStudents(string searchValue)
        {
            List <ISUser> users = new List <ISUser>();

            using (MySqlConnection conn = DBUtils.GetConnection())
            {
                try
                {
                    conn.Open();

                    using (var command = new MySqlCommand($"SELECT * FROM users WHERE role = 'student' AND fullName REGEXP '{searchValue}'", conn))
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                ISUser user = _ReadUserStream(reader);;
                                users.Add(user);
                            }

                            return(users);
                        }
                }
                catch (Exception err)
                {
                    MessageBox.Show("Error: " + err.Message, "Ошибка!");
                }
            }

            return(null);
        }
コード例 #2
0
ファイル: DBUsers.cs プロジェクト: Rubell1on/DormitoryIS
        public static ISUser Login(string userName, string password)
        {
            ISUser user = null;

            using (MySqlConnection conn = DBUtils.GetConnection())
            {
                try
                {
                    conn.Open();

                    using (var command = new MySqlCommand($"SELECT * FROM users WHERE username='******' AND password='******'", conn))
                        using (var reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                user = _ReadUserStream(reader);
                                return(user);
                            }
                        }
                }
                catch (Exception err)
                {
                    MessageBox.Show("Error: " + err.Message, "Ошибка!");
                }
            }

            return(null);
        }
コード例 #3
0
ファイル: DBUsers.cs プロジェクト: Rubell1on/DormitoryIS
        public static ISUser GetUserById(int userId)
        {
            ISUser user = null;

            using (MySqlConnection conn = DBUtils.GetConnection())
            {
                try
                {
                    conn.Open();

                    using (var command = new MySqlCommand($"SELECT * FROM users WHERE id ='{userId}'", conn))
                        using (var reader = command.ExecuteReader())
                        {
                            if (reader.Read())
                            {
                                user = _ReadUserStream(reader);
                                return(user);
                            }
                        }
                }
                catch (Exception err)
                {
                    MessageBox.Show("Error: " + err.Message, "Ошибка!");
                }
            }

            return(null);
        }
コード例 #4
0
 private void _SetMainInfo(ISUser user)
 {
     userIdField.Text    = user.Id.ToString();
     birthDateField.Text = user.DateOfBirth.Split(' ')[0];
     fullNameField.Text  = user.FullName;
     genderField.Text    = user.Gender == ISGenders.male ? "Мужской" : "Женский";
     roleField.Text      = Utils.GetRoleString(user.Role);
 }
コード例 #5
0
ファイル: AccountController.cs プロジェクト: alexa984/KT
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                string path  = System.Web.HttpContext.Current.Server.MapPath("~/Content/Images/Default-Profile.jpg");
                byte[] photo = System.IO.File.ReadAllBytes(path);
                model.Image = photo;


                var user = new ISUser
                {
                    FirstName = model.FirstName,
                    LastName  = model.LastName,
                    UserName  = model.Email,
                    Email     = model.Email,
                    Image     = model.Image
                };

                var result = await UserManager.CreateAsync(user, model.PasswordHash);



                if (result.Succeeded)
                {
                    var userWithId = await UserManager.FindByNameAsync(user.UserName);

                    var userId      = userWithId.Id;
                    var roleStore   = new RoleStore <IdentityRole>(context);
                    var roleManager = new RoleManager <IdentityRole>(roleStore);
                    var userStore   = new UserStore <ISUser>(context);
                    var userManager = new UserManager <ISUser>(userStore);
                    userManager.AddToRole(userId, "User");
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
コード例 #6
0
        private void _SetUsersGrid(List <ISUser> users)
        {
            if (usersGrid.Rows.Count > 0)
            {
                usersGrid.Rows.Clear();
            }

            if (users != null && users.Count > 0)
            {
                for (int i = 0; i < users.Count; i++)
                {
                    ISUser user = users[i];

                    string   role        = Utils.GetRoleString(user.Role);
                    string   dateOfBirth = user.DateOfBirth.Split(' ')[0];
                    string   gender      = user.Gender == ISGenders.male ? "Мужской" : "Женский";
                    string[] row         = new string[] { (i + 1).ToString(), user.Id.ToString(), user.FullName, dateOfBirth, role, gender, user.GroupId, user.RoomId.ToString() };

                    usersGrid.Rows.Add(row);
                }
            }
        }
コード例 #7
0
        private void authorizeButton_Click(object sender, EventArgs e)
        {
            if (loginInput.Text != "" && passwordInput.Text != "")
            {
                ISUser user = DBUsers.Login(loginInput.Text, passwordInput.Text);

                if (user != null)
                {
                    switch (user.Role)
                    {
                    case ISRoles.admin:
                        break;

                    case ISRoles.comendant:
                        ComendantMainForm comendantForm = new ComendantMainForm(user);
                        comendantForm.FormClosed += (obj, ev) => Show();
                        Hide();
                        comendantForm.Show();
                        break;

                    case ISRoles.student:
                        StudentMainForm stundetForm = new StudentMainForm(user);
                        stundetForm.FormClosed += (obj, ev) => Show();
                        Hide();
                        stundetForm.Show();
                        break;
                    }
                }
                else
                {
                    MessageBox.Show("Неправильная пара логин/пароль", "Ошибка!");
                }
            }
            else
            {
                MessageBox.Show("Необходимо ввести логин и пароль!", "Ошибка!");
            }
        }
コード例 #8
0
ファイル: AccountController.cs プロジェクト: alexa984/KT
        public async Task <ActionResult> ExternalLoginConfirmation(ExternalLoginConfirmationViewModel model, string returnUrl)
        {
            if (User.Identity.IsAuthenticated)
            {
                return(RedirectToAction("Index", "Manage"));
            }

            if (ModelState.IsValid)
            {
                // Get the information about the user from the external login provider
                var info = await AuthenticationManager.GetExternalLoginInfoAsync();

                if (info == null)
                {
                    return(View("ExternalLoginFailure"));
                }
                var user = new ISUser {
                    UserName = model.Email, Email = model.Email
                };
                var result = await UserManager.CreateAsync(user);

                if (result.Succeeded)
                {
                    result = await UserManager.AddLoginAsync(user.Id, info.Login);

                    if (result.Succeeded)
                    {
                        await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                        return(RedirectToLocal(returnUrl));
                    }
                }
                AddErrors(result);
            }

            ViewBag.ReturnUrl = returnUrl;
            return(View(model));
        }
コード例 #9
0
        private void _SetRoomInfo(ISRoom room, List <ISUser> roomMates)
        {
            dormitoryNameField.Text = room.DormitoryName;
            roomNumField.Text       = room.RoomName;
            addressField.Text       = room.Address;

            if (roomMatesGrid.Rows.Count > 0)
            {
                roomMatesGrid.Rows.Clear();
            }

            if (roomMates.Count > 0)
            {
                for (int i = 0; i < roomMates.Count; i++)
                {
                    ISUser   u   = roomMates[i];
                    string[] row = new string[3] {
                        (i + 1).ToString(), u.FullName, u.GroupId
                    };
                    roomMatesGrid.Rows.Add(row);
                }
            }
        }
コード例 #10
0
ファイル: DBRooms.cs プロジェクト: Rubell1on/DormitoryIS
        public static List <ISUser> GetRoomMates(ISUser user)
        {
            List <ISUser> roomMates = new List <ISUser>();

            using (MySqlConnection conn = DBUtils.GetConnection())
            {
                try
                {
                    conn.Open();

                    string query = $"SELECT * FROM users WHERE id != '{user.Id}' AND roomId = '{user.RoomId}'";
                    using (var command = new MySqlCommand(query, conn))
                        using (var reader = command.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                int       id              = Convert.ToInt32(reader[0]);
                                string    fullName        = reader[1].ToString();
                                string    dateOfBirth     = reader[2].ToString();
                                ISRoles   role            = (ISRoles)Enum.Parse(typeof(ISRoles), reader[3].ToString());
                                ISGenders gender          = (ISGenders)Enum.Parse(typeof(ISGenders), reader[4].ToString());
                                string    groupId         = reader[5].ToString();
                                int       studentTicketId = Convert.ToInt32(reader[6]);
                                int       roomId          = Convert.ToInt32(reader[9]);

                                roomMates.Add(new ISUser(id, fullName, dateOfBirth, role, gender, groupId, studentTicketId, roomId));
                            }
                        }
                }
                catch (Exception err)
                {
                    MessageBox.Show("Error: " + err.Message, "Ошибка!");
                }
            }

            return(roomMates);
        }
コード例 #11
0
 private void SetMainTab()
 {
     user = DBUsers.GetUserById(user.Id);
     _SetMainInfo(user);
 }
コード例 #12
0
 public StudentMainForm(ISUser user)
 {
     this.user = user;
     InitializeComponent();
     InitForm();
 }
コード例 #13
0
ファイル: AddUserForm.cs プロジェクト: Rubell1on/DormitoryIS
 public AddUserForm(ISUser user)
 {
     this.user = user;
     InitializeComponent();
     InitForm();
 }
コード例 #14
0
 public ChangePasswordForm(ISUser user)
 {
     this.user = user;
     InitializeComponent();
     InitForm();
 }
コード例 #15
0
 public AddCardForm(ISUser user)
 {
     this.user = user;
     InitializeComponent();
 }