Example #1
0
        //henter ut en UserModel med Users.email lik email
        public UserModel get(string email)
        {
            var userModel = new UserModel();
            using (var db = new CustomerContext())
            {
                try
                {
                    var user = (from u in db.Users
                                where u.username.Equals(email)
                                select u).FirstOrDefault();
                    if (user == null)//tester om brukeren finnes
                        return null;

                    userModel.ID = user.personID;
                    userModel.passwordHash = user.password;
                    userModel.username = user.username;
                    return userModel;
                }
                catch (Exception ex)
                {
                    _logging.logToDatabase(ex);
                }
                return null;
            }
        }
        public ActionResult createEmployee(EmployeeModel employee)
        {
            if (!ModelState.IsValid)
                return View();
            string username = employee.username + "@kaffeplaneten.no";
            var userModel = _userBLL.get(username);
            if (userModel != null)
            {
                Session["userExists"] = "Brukernavn(Epost) du prøver å registere finnes allerede!";
                return View(employee);
            }
            var personExist = _employeeBLL.find(username);
            if (personExist != null)
            {
                Session["employeeExists"] = "Ansattbrukeren eksisterer allerede!";
                return View(employee);
            }
            if (!_employeeBLL.add(employee))
            {
                Session["employeeError"] = "Feil ved registrering av ansatt";
                return View(employee);
            }
            userModel = new UserModel();
            userModel.username = username;
            userModel.passwordHash = base.getHash(employee.password);
            userModel.ID = employee.employeeID;

            if (!_userBLL.add(userModel)) //registrerer ny bruker
            {
                Session["userError"] = "Feil ved registrering av bruker";
                return View(employee);
            }
            _loggingBLL.logToUser("La til ny ansatt: " + userModel.username, (EmployeeModel)Session["Employee"]);
            return RedirectToAction("AllEmployees", "AdminEmployee");
        }
 public ActionResult HeaderAndMenuBar(UserModel user)
 {
     if (Session[LOGGED_INN] != null && (bool)Session[LOGGED_INN])
         ViewBag.Inlogged = true;
     ViewBag.notInlogged = false;
     return PartialView(user);
 }
Example #4
0
 public bool update(UserModel userModel)
 {
     if (userModel.username.Equals("false"))
         return false;
     if (userModel.ID > 0)
         return true;
     return false;
 }
Example #5
0
 public UserModel get(int id)
 {
     if (id < 0)
         return null;
     var userModel = new UserModel();
     userModel.ID = 1;
     userModel.password = "******";
     userModel.username = "******";
     return userModel;
 }
Example #6
0
 public UserModel get(string email)
 {
     if (email.Equals("@kaffeplaneten.no") || email.Equals("*****@*****.**"))
         return null;
     var userModel = new UserModel();
     userModel.ID = 1;
     userModel.password = "******";
     userModel.username = email;
     return userModel;
 }
 public void HeaderAndMenuBarTestLoggedInn()
 {
     //Arrange
     var controller = MockHttpSession.getMoqLayoutController();
     controller.Session["LoggedInn"] = true;
     var userModel = new UserModel();
     userModel.ID = 1;
     userModel.password = "******";
     userModel.username = "******";
     //Act
     var result = (PartialViewResult)controller.HeaderAndMenuBar(userModel);
     var resultModel = (UserModel)result.Model;
     //Assert
     Assert.AreEqual(result.ViewName, "");
     Assert.AreEqual(resultModel.ID, userModel.ID);
     Assert.AreEqual(resultModel.password, userModel.password);
     Assert.AreEqual(resultModel.username, userModel.username);
 }
Example #8
0
        //Legger en Users inn i databasen
        public bool add(UserModel userModel)
        {
            using (var db = new CustomerContext())
            {
                try
                {
                    var user = (from u in db.Users
                                where u.username.Equals(userModel.username)
                                select u).FirstOrDefault();
                    if (user != null)
                        return false;
                    user = new Users()
                    {
                        username = userModel.username,
                        password = userModel.passwordHash
                    };
                    user.person = (from c in db.Customers
                                   where c.email.Equals(userModel.username)
                                   select c).SingleOrDefault();
                    if (user.person == null)//tester om Users sin customer finnes
                    {
                        user.person = (from e in db.Employees
                                       where e.email.Equals(userModel.username)
                                       select e).SingleOrDefault();
                        if (user.person == null)//tester om Users sin admin finnes
                        {
                            return false;
                        }
                    }

                    db.Users.Add(user);
                        db.SaveChanges();
                    return true;
                }
                catch (Exception ex)
                {
                    _logging.logToDatabase(ex);
                }
                return false;
            }//end using
        }
        public ActionResult createUser(CustomerModel newCustomer)
        {
            if (!ModelState.IsValid)
                return View();

            var userModel = _userBLL.get(newCustomer.email);
            if (userModel != null)//tester om en bruker med samme epost finnes fra før
            {
                ModelState.AddModelError("", "Eposten du prøver å registrere finnes allerede. Vennligst benytt en annen adresse");
                _loggingBLL.logToUser("Prøvde å registrere seg med eksisterende epost: " + userModel.username, (CustomerModel)Session[CUSTOMER]);
                return View(newCustomer);
            }

            if (!_customerBLL.add(newCustomer))//registrerer ny customer
            {
                ModelState.AddModelError("", "Feil ved registrering av bruker");
                _loggingBLL.logToUser("Fikk en feil ved registrering av brukernavn: " + newCustomer.email, (CustomerModel)Session[CUSTOMER]);
                return View(newCustomer);
            }

            userModel = new UserModel();
            userModel.username = newCustomer.email;
            userModel.passwordHash = getHash(newCustomer.password);
            userModel.ID = newCustomer.customerID;

            if (!_userBLL.add(userModel))//registrerer ny user
            {
                ModelState.AddModelError("", "Feil ved registrering av bruker");
                _loggingBLL.logToUser("Fikk en feil ved registrering av brukernavn: " + userModel.username, (CustomerModel)Session[CUSTOMER]);
                return View(newCustomer);
            }

            _loggingBLL.logToUser("Opprettet bruker: " + newCustomer.email, (CustomerModel)Session[CUSTOMER]);
            _loggingBLL.logToDatabase("Bruker lagt til i database: " + newCustomer.email);
            return RedirectToAction("Loginview", "Security", new { area = "" });
        }
Example #10
0
 public bool add(UserModel userModel)
 {
     if (userModel.ID > 0)
         return true;
     return false;
 }
        public ActionResult Loginview(UserModel user)
        {
            user.passwordHash = base.getHash(user.password);
            if (_userBLL.verifyUser(user))
            {
                Session[LOGGED_INN] = true;
                ViewBag.LoggedOn = true;
                Session[CUSTOMER] = _customerBLL.find(user.username);
                _LoggingBLL.logToUser("Logget inn i systemet.", (CustomerModel)Session[CUSTOMER]);
                return RedirectToAction("AllProducts", "Product", user.username);

            }
            ModelState.AddModelError("", "Feil brukernavn eller passord");
            CustomerModel nothing = null;
            _LoggingBLL.logToUser("Prøvde å logge seg inn på systemet med feil brukernavn/passord.", nothing);
            return View();
        }
Example #12
0
 public bool resetPassword(UserModel user, byte[] randomPW)
 {
     if (user.ID < 0)
         return false;
     return true;
 }
Example #13
0
 //Oppdaterer Users data med dataen i userModel
 public bool update(UserModel userModel)
 {
     return _userDAL.update(userModel);
 }
Example #14
0
 public bool verifyUser(UserModel userModel)
 {
     if (userModel.ID > 0)
         return true;
     return false;
 }
Example #15
0
 //Oppdaterer Users data med dataen i userModel
 public bool update(UserModel userModel)
 {
     using (var db = new CustomerContext())
     {
         try
         {
             var user = db.Users.Find(userModel.ID);
             if (user == null)//tester om brukeren finnes
                 return false;
             user.person = db.Persons.Find(userModel.ID);
             if(!userModel.username.Equals(user.username))
             {
                 var email = (from p in db.Users
                              where p.username.Equals(userModel.username)
                              select p).FirstOrDefault();
                 if (email != null)//tester om epostadressen finnes fra før
                     return false;
                 user.username = userModel.username;
             }
             user.password = null;
             user.password = userModel.passwordHash;
             db.SaveChanges();
             return true;
         }
         catch (Exception ex)
         {
             _logging.logToDatabase(ex);
         }
         return false;
     }
 }
Example #16
0
 //Bekrefter brukernavn og passord for user
 public bool verifyUser(UserModel userModel)
 {
     using (var db = new CustomerContext())
     {
         try
         {
             var user = (from u in db.Users
                         where u.password == userModel.passwordHash && u.username == userModel.username
                         select u).SingleOrDefault();
             if (user == null)
                 return false;
             return true;
         }
         catch (Exception ex)
         {
             _logging.logToDatabase(ex);
         }
         return false;
     }//end using
 }
Example #17
0
 public static UserModel createSuperUser()
 {
     var user = new UserModel();
     user.username = "******";
     user.passwordHash = createHash("Sjefesen123");
     return user;
 }
Example #18
0
 //henter ut en UserModel fra User med customerID lik id
 public UserModel get(int id)
 {
     var userModel = new UserModel();
     using (var db = new CustomerContext())
     {
         try
         {
             var user = db.Users.Find(id);
             if (user == null)
                 return null;
             userModel.ID = id;
             userModel.passwordHash = user.password;
             userModel.username = user.username;
             return userModel;
         }
         catch (Exception ex)
         {
             _logging.logToDatabase(ex);
         }
         return null;
     }//end using
 }
 public void LoginviewTestPostWrongUser()
 {
     //Arrange
     var controller = MockHttpSession.getMoqSecurityController();
     var user = new UserModel();
     user.ID = 1;
     user.username = "******";
     //Act
     var result = (ViewResult)controller.Loginview(user);
     //Assert
     Assert.AreEqual(result.ViewName, "");
 }
 public void LoginviewTestPostOK()
 {
     //Arrange
     var controller = MockHttpSession.getMoqSecurityController();
     var user = new UserModel();
     user.ID = 1;
     user.username = "******";
     //Act
     var result = (RedirectToRouteResult)controller.Loginview(user);
     //Assert
     Assert.AreEqual(result.RouteName, "");
     Assert.AreEqual(result.RouteValues.Values.First(), "Home");
 }
Example #21
0
 //Bekrefter brukernavn og passord for user
 public bool verifyUser(UserModel userModel)
 {
     return _userDAL.verifyUser(userModel);
 }
Example #22
0
 //Legger en Users inn i databasen
 public bool add(UserModel userModel)
 {
     return _userDAL.add(userModel);
 }
        public ActionResult Loginview(UserModel user)
        {
            user.passwordHash = base.getHash(user.password);
            if (_userBLL.verifyUser(user))
            {
                Session[LOGGED_INN] = true;
                ViewBag.LoggedOn = true;
                EmployeeModel Emp = _EmployeeBLL.find(user.username);
                if(Emp != null)
                {
                    Session[Employee] = Emp;
                        Session[employeeAdmin] = Emp.employeeAdmin;
                        Session[customerAdmin] = Emp.customerAdmin;
                        Session[orderAdmin] = Emp.orderAdmin;
                        Session[productAdmin] = Emp.productAdmin;
                        Session[databaseAdmin] = Emp.databaseAdmin;

                    Session[firstname] = Emp.firstName;
                    Session[lastname] = Emp.lastName;
                    Session[username] = user.username;
                    _loggingBLL.logToUser("Logget seg på systemet.", (EmployeeModel)Session["Employee"]);
                    return RedirectToAction("Home", "Layout");
                }
                Session[Feilmelding] = "Finner ikke brukerepost";
                return View();
            }
            Session[Feilmelding] = "Feil i brukernavn eller passord";
            _loggingBLL.logToUser("Prøvde å logge seg inn på systemet med feil brukernavn/passord.", (EmployeeModel)null);
            return View();
        }