Esempio n. 1
0
        public ActionResult Index(PersonRegisterVM UserLog)
        {
            //string a = student.Email;
            if (!ModelState.IsValid)
            {
                // TODO : Extract predicates for authentication to  avoid duplication above



                Person aPerson = db.People.FirstOrDefault(x => x.Email == UserLog.Email && x.Password == UserLog.Password);


                if (aPerson == null)
                {
                    //return HttpNotFound("Email Non Correcte");
                    TempData["ErrorMessage"] = "Invalid Email or Password";
                    return(RedirectToAction(nameof(Index)));
                }
                if (aPerson is Student)
                {
                    Student st = new Student();
                    Session["User"] = st;
                    return(RedirectToAction(actionName: "Index", controllerName: "Home"));
                }

                if (aPerson is Instructor)
                {
                    Instructor inst = new Instructor();
                    Session["User"] = inst;
                    return(RedirectToAction(actionName: "Index", controllerName: "Home"));
                }
            }
            return(View());
        }
Esempio n. 2
0
 public bool AccountExist(PersonRegisterVM TestAccount)
 {
     if (db.People.Any(m => m.Email == TestAccount.Email))
     {
         return(true);
     }
     return(false);
 }
Esempio n. 3
0
        public Person RegisteringNewAccount(PersonRegisterVM TestAccount)

        {
            var photo = new FilePath
            {
                FileName = TestAccount.ImagePath,
                FileType = TestAccount.ImageType
            };

            if (TestAccount.Role == "1")
            {
                Student st = new Student();

                st.Email          = TestAccount.Email;
                st.LastName       = TestAccount.LastName;
                st.FirstMidName   = TestAccount.FirstName;
                st.Password       = TestAccount.Password;
                st.EnrollmentDate = DateTime.Now;
                st.FilePaths      = new List <FilePath>();
                st.FilePaths.Add(photo);

                db.Students.Add(st);
                db.SaveChanges();


                return(st);
            }
            else                                                             //(TestAccount.Role == "2")
            {
                Instructor ins = new Instructor();
                ins.Email        = TestAccount.Email;
                ins.LastName     = TestAccount.LastName;
                ins.FirstMidName = TestAccount.FirstName;
                ins.Password     = TestAccount.Password;
                ins.HireDate     = DateTime.Now;

                ins.FilePaths = new List <FilePath>();
                ins.FilePaths.Add(photo);

                db.Instructors.Add(ins);
                db.SaveChanges();

                return(ins);
            }
        }
Esempio n. 4
0
        public void Register_Account_With_Login_And_Good_Password_Success()
        {
            PersonRegisterVM newAccount = new PersonRegisterVM();

            newAccount.FirstName = "test1";
            newAccount.LastName  = "test1";
            newAccount.Role      = "1";
            newAccount.Email     = "*****@*****.**";
            newAccount.Password  = "******";
            newAccount.ImagePath = "~/si.png";
            newAccount.ImageType = "image/png";

            BAL.StudentBAL bal = new BAL.StudentBAL(dbContext);

            bal.RegisteringNewAccount(newAccount);

            Student st = this.dbContext.Students.FirstOrDefault(e => e.Email == newAccount.Email);


            Assert.That(st != null);
        }
Esempio n. 5
0
        public void Register_Account_With_Exist_Mail_Fail()
        {
            PersonRegisterVM newAccount = new PersonRegisterVM();

            newAccount.FirstName = "yahya";
            newAccount.LastName  = "khoder";
            newAccount.Role      = "1"; // to test the registring of student or ="2" for isntructor
            newAccount.Email     = "*****@*****.**";
            newAccount.Password  = "******";
            newAccount.ImagePath = "~/si.png";
            newAccount.ImageType = "image/png";

            BAL.StudentBAL bal = new BAL.StudentBAL(dbContext);

            bal.AccountExist(newAccount);

            Student st = this.dbContext.Students.FirstOrDefault(e => e.Email == newAccount.Email);



            Assert.That(st != null);
        }
Esempio n. 6
0
        public void Register_Account_With_Path_Image_Success()
        {
            //Test with images crieteras in progress

            PersonRegisterVM newAccount = new PersonRegisterVM();

            newAccount.FirstName = "test1";
            newAccount.LastName  = "test1";
            newAccount.Role      = "1";
            newAccount.Email     = "*****@*****.**";
            newAccount.Password  = "******";
            newAccount.ImagePath = "~/si.png";
            newAccount.ImageType = "image/png";

            BAL.StudentBAL bal = new BAL.StudentBAL(dbContext);



            Student st = this.dbContext.Students.FirstOrDefault(e => e.FilePaths.Any(c => c.FileName == newAccount.ImagePath));


            Assert.That(st != null);
        }
Esempio n. 7
0
        public ActionResult Register(PersonRegisterVM User, HttpPostedFileBase Image)
        {
            //an object to have access to the tests methodes
            BAL.StudentBAL aStudent = new BAL.StudentBAL(db);

            //proprities of image to give of view model
            User.ImagePath = System.IO.Path.GetFileName(Image.FileName);
            User.ImageType = Image.ContentType;


            if (ModelState.IsValid)
            {
                //prepraing  a test
                // aStudent.TestRegisteringStudentExist(User, db);

                if (aStudent.AccountExist(User))
                {
                    TempData["errorMail"] = "Email exist already!";
                    return(RedirectToAction("Register"));
                }

                //ulpoading image png and jpg

                //supporting an image
                if (Image != null && 0 < Image.ContentLength)
                {
                    //accessible image format

                    var validImageTypes = new List <string>()
                    {
                        "image/png", "image/jpeg"
                    };

                    //only format png and jpg

                    //old way with enum
                    if (!validImageTypes.Contains(Image.ContentType))
                    {
                        TempData["ErrorUploading"] = "Format Image not supported!";
                        return(RedirectToAction("Register"));
                    }

                    //MAxByteValue 100kb;
                    if (Image.ContentLength > 100 * 1000)
                    {
                        TempData["ErrorUploadingTaille"] = "Size Image not supported!";
                        return(RedirectToAction("Register"));
                    }
                    //My Register method for a new student account and adding the person to a session to keep it Login

                    Session["User"] = aStudent.RegisteringNewAccount(User);



                    return(RedirectToAction(nameof(Index), "Student"));
                }
            }



            List <SelectListItem> myList = new List <SelectListItem>();

            myList.Add(new SelectListItem {
                Value = "1", Text = "Student"
            });
            myList.Add(new SelectListItem {
                Value = "2", Text = "Instructor"
            });

            //myList = data.ToList();

            ViewBag.liste = myList;
            return(View());

            //return RedirectToAction("Register");
        }
Esempio n. 8
0
 public bool RegisteringImage(string aPath, PersonRegisterVM TestAccount)
 {
     return((aPath == System.IO.Path.GetFileName(TestAccount.ImagePath)) ? true : false);
 }