Пример #1
0
        public async Task <IActionResult> Edit(int id, [Bind("LoginTrailId,LogInId,LogInTime,LogOutTime")] LoginTrail loginTrail)
        {
            if (id != loginTrail.LoginTrailId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(loginTrail);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LoginTrailExists(loginTrail.LoginTrailId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LogInId"] = new SelectList(_context.Login, "LoginId", "LoginId", loginTrail.LogInId);
            return(View(loginTrail));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("LoginTrailId,LogInId,LogInTime,LogOutTime")] LoginTrail loginTrail)
        {
            if (ModelState.IsValid)
            {
                _context.Add(loginTrail);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LogInId"] = new SelectList(_context.Login, "LoginId", "LoginId", loginTrail.LogInId);
            return(View(loginTrail));
        }
    public ReturnBool LoginTrail_new(LoginTrail lt)
    {
        query = @" INSERT INTO login_trail (user_id,client_ip,client_os,client_browser, useragent) 
                  VALUES (@user_id, @client_ip, @client_os, @client_browser, @useragent)";
        MySqlParameter[] pr = new MySqlParameter[] {
            new MySqlParameter("user_id", lt.User_Id),
            new MySqlParameter("client_ip", lt.Client_Ip),
            new MySqlParameter("client_os", lt.Client_Os),
            new MySqlParameter("client_browser", lt.Client_Browser),
            new MySqlParameter("useragent", lt.UserAgent)
        };

        rb = db.executeInsertQuery(query, pr);
        return(rb);
    }
Пример #4
0
    public void fn_logintrail(bool flag)
    {
        LoginTrail lt1 = new LoginTrail();
        HttpBrowserCapabilities browser = Request.Browser;
        OperatingSystem         os      = Environment.OSVersion;

        lt1.User_Id   = txt_login.Text.Trim();
        lt1.Client_Ip = util.GetClientIpAddress(this.Page);
        lt1.UserAgent = Request.UserAgent;
        if (lt1.UserAgent.Contains("Edge"))
        {
            lt1.Client_Browser = "Microsoft Edge " + browser.Version;
        }
        else
        {
            lt1.Client_Browser = browser.Type;
        }
        lt1.Client_Os = os.VersionString;


        rb = dl.LoginTrail_new(lt1);
    }
Пример #5
0
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> LoginUser(Dashboard dashboard)
        {
            //Check if model is valid
            if (ModelState.IsValid)
            {
                //Get & store inputs
                String inputUsername = HttpContext.Request.Form["Username"];
                String inputPassword = HttpContext.Request.Form["Password"];

                //Create String to store List of logins
                String loginList = "";

                //Create variables to store data
                int      employeeID = 0;
                int      loginID    = 0;
                DateTime loginDate  = DateTime.Now;
                bool     isMatch    = false;
                String   role       = "";

                //Store List of existing Login details
                var loginDetails = from lD in _context.Login
                                   select lD;

                //Loop through List of existing login details
                foreach (var login in loginDetails)
                {
                    //Compare inputs
                    if (login.Username.ToString().Equals(inputUsername) &&
                        login.Password.ToString().Equals(inputPassword))
                    {
                        //Store data
                        employeeID = login.EmployeeId;
                        loginID    = login.LoginId;

                        //Set boolean
                        isMatch = true;

                        /*
                         * //Print message
                         * return Content(LOG_TAG + ": Alright !" +
                         *  "\nThe inputs and login details are equal" +
                         *  "\nInputs" +
                         *  "\n- Username: "******"\n- Password: "******"\nLogin Details" +
                         *  "\n- Username: "******"\n- Password: "******"\n- Employee ID: " + login.EmployeeId +
                         *  "\n- Login ID: " + login.LoginId
                         * );
                         */
                    }

                    /*
                     * //Store logins
                     * loginList += "Employee ID: " + login.EmployeeId + ": " +
                     *  "\n- Login ID: " + login.LoginId +
                     *  "\n- Username: "******"\n- Password: "******"\n\n";
                     */
                }

                //Check boolean value
                if (isMatch == true)
                {
                    //Set new values for login trails
                    var employeLoginTrail = new LoginTrail
                    {
                        LogInId   = loginID,
                        LogInTime = loginDate
                    };

                    //Use context to add recored in login trails
                    _context.LoginTrail.Add(employeLoginTrail);
                    _context.SaveChanges();

                    //Store query
                    var employeeDetails = from emp in _context.Employees
                                          join l in _context.Login
                                          on emp.EmployeeId equals l.EmployeeId
                                          where emp.EmployeeId == employeeID
                                          select emp;

                    //Loop through List
                    foreach (var detail in employeeDetails)
                    {
                        //Check employee role
                        if (detail.UserRole.Equals("Admin"))
                        {
                            //Redirect to dashboard & pass employee ID
                            return(RedirectToAction("AdminDashboard", "Dashboard", new { id = employeeID }));
                        }
                        else if (detail.UserRole.Equals("Manager"))
                        {
                            //Redirect to dashboard & pass employee ID
                            return(RedirectToAction("ManagerDashboard", "Dashboard", new { id = employeeID }));
                        }
                        else if (detail.UserRole.Equals("Employee"))
                        {
                            //Redirect to dashboard & pass employee ID
                            return(RedirectToAction("EmployeeDashboard", "Dashboard", new { id = employeeID }));
                        }

                        /*
                         * //Print message
                         * return Content(LOG_TAG + ": Logged In Employee Details" +
                         *  "\n- Role: " + detail.UserRole
                         * );
                         */
                    }
                }
                else
                {
                    //Print error
                }

                /*
                 * //Print message
                 * return Content(LOG_TAG + ": List of existing Login Details content" +
                 *  "\n" + loginList
                 * );
                 */
            }

            //Redirect to view
            return(View("~/Views/Logins/Index.cshtml"));
        }