Пример #1
0
        private void LoginButton_Click(object sender, EventArgs e)
        {
            //validate user input
            if (Validation.isCredentialValid(usernameTxtBox, passwordTxtBox, errorProvider1))
            {
                string      errorMsg;
                UserConnect userConnect = new UserConnect();

                userRole = userConnect.Login(usernameTxtBox.Text.Trim(), passwordTxtBox.Text.Trim(), out errorMsg);
                if (!userConnect.isLoginSuccessfull)
                {
                    errorProvider1.SetError(usernameTxtBox, "Invalid Username or Password"); return;
                }
                switch (userRole)
                {
                case Models.Objects.UserObject.UserRole.Admin:

                    Forms.Admin.AdminContainer adminContainer = new Forms.Admin.AdminContainer();
                    adminContainer.AdminFullName = userConnect.fullName;
                    this.Hide();
                    adminContainer.Show();

                    break;

                case Models.Objects.UserObject.UserRole.Instructor:

                    Forms.Instructor.InstructorContainer instructorContainer = new Forms.Instructor.InstructorContainer();
                    instructorContainer.InstructorFullName = userConnect.fullName;
                    this.Hide();
                    instructorContainer.Show();

                    break;

                case Models.Objects.UserObject.UserRole.Student:

                    Forms.Student.StudentContainer studentContainer = new Forms.Student.StudentContainer();
                    studentContainer.StudentFullName = userConnect.fullName;
                    this.Hide();
                    studentContainer.Show();

                    break;

                default:
                    break;
                }
            }
            //if valid get user fullName and open Admin, Instructor or Student form
            //else show error msg
        }
Пример #2
0
        public ActionResult Login(string username, string password)
        {
            UserConnect  uc      = new UserConnect();
            LoginMessage message = uc.Login(username, password);

            if (message.GetResult())
            {
                Globals.PRESENT_USER = message.GetUser();
                return(View("~/Views/Home/Index.cshtml"));
            }
            else
            {
                ViewBag.serverResponse = message.GetText();
                return(View("Index"));
            }
        }