Exemple #1
0
        /// <summary>
        /// Authenticate an user and set cookie if user is valid.
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool Login(User user)
        {
            // Return true if user exist
            var result = _userRepository.IsAdminExist(user.Username, user.Password);

            // Return all fields on sgbd user if username matches
            var userdata = _userRepository.getUser(user.Username);

            // If user doesn't exist, verify that he fill correctly the form
            if (result)
            {
                //FormsAuthentication.SetAuthCookie(username, false);
                HttpCookie usernameCookie = new HttpCookie("Username");
                HttpCookie pwdCookie = new HttpCookie("Password");
                HttpCookie sessionCookie = new HttpCookie("Session");

                // set Expiration date
                usernameCookie.Expires = DateTime.Now.AddDays(1d);
                pwdCookie.Expires = DateTime.Now.AddDays(1d);
                sessionCookie.Expires = DateTime.Now.AddDays(1d);

                // Set Value on cookies
                usernameCookie.Value = userdata.Username;
                pwdCookie.Value = userdata.Password;
                sessionCookie.Value = Convert.ToString(userdata.Session);

            }

          return result;
        }
Exemple #2
0
        /// <summary>
        /// Insert the user in DB
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public bool insert(User user)
        {
            var result = _session.CreateQuery("INSERT INTO User(firstName,lastName,Email,username,password,active,session_code) "
                + "VALUES (" + user.firstName + "," + user.lastName + "," + user.Email + "," + user.Username + ","
                        + user.Password + "," + user.Active + "," + user.Session + ")");

            var flags = Convert.ToBoolean(result);
            return flags;
        }
Exemple #3
0
        // Function that verify if admin exist
        public bool IsAdminExist(IUserRepository userRepository, User user)
        {
            this.user = user;

            // Get Result
            bool flags = userRepository.IsAdminExist(user.Username, user.Password);

            return flags;
        }
    public ActionResult Login(User model, string returnUrl)
    {

      if (ModelState.IsValid && _authProvider.Login(model))
      {
        return RedirectToUrl(returnUrl);
      }

      ModelState.AddModelError("", "The user name or password provided is incorrect.");

      return View(model);
    }
Exemple #5
0
        // Function that insert user in DB
        public bool registration(IUserRepository userRepository, User user)
        {
            this.user = user;

            // We verify that user exist or not in our DB
            if ((!IsUserExist(userRepository, user)) || (!IsAdminExist(userRepository, user)))
            {
                bool flags = userRepository.insert(user);
                return flags;
            }
            return false;
        }
 public ActionResult LogOn(User model, string returnUrl)
 {
     UserModel um = new UserModel(model);
     if (ModelState.IsValid)
     {
         // Verify if user loggin is true
         if (_authProvider.Login(model))
         {
             //FormsAuthentication.RedirectFromLoginPage("", false);
             return RedirectToUrl(returnUrl);
         }
         else
         {
             ModelState.AddModelError("", "Username or Password Incorrect");
         }
     }
     return View(model);
 }
Exemple #7
0
 // Constructor
 public UserModel(User USER)
 {
     this.user = USER;
     user = new User();
 }