Ejemplo n.º 1
0
        /*  LOG OUT PROCESS  */
        public IActionResult LogOut()
        {
            LogHistorie logHistorie = new LogHistorie
            {
                clientID  = HttpContext.Session.GetInt32("LogedIn").GetValueOrDefault(0),
                date      = DateTime.Now,
                logStatus = (char)SignController.LogStatus.Out,
            };

            _context.LogHistories.Add(logHistorie);
            _context.SaveChanges();

            HttpContext.Session.Clear();

            return(RedirectToAction("Index", "Sign"));
        }
        public IActionResult SignInProcess(string email, string password, string remember)
        {
            if (_context.ClientUsers.Where(w => w.email == email.Trim()).Count() > 0)
            {
                ClientUser client = _context.ClientUsers.Include(s => s.Company).Where(w => w.email == email.Trim()).FirstOrDefault();

                if (Hash.Validate(password.Trim(), client.token, client.password))
                {
                    if (client.isActive == false)
                    {
                        if (client.Company.isActive == false)
                        {
                            HttpContext.Session.SetInt32("inactive", 1);
                        }
                        else
                        {
                            HttpContext.Session.SetInt32("inactive", 2);
                        }

                        return(RedirectToAction("Index", "Sign"));
                    }

                    HttpContext.Session.SetInt32("LogedIn", client.id);

                    LogHistorie logHistorie = new LogHistorie
                    {
                        clientID  = client.id,
                        date      = DateTime.Now,
                        logStatus = (char)LogStatus.In,
                    };
                    _context.LogHistories.Add(logHistorie);
                    _context.SaveChanges();

                    HttpContext.Session.SetString("fullname", client.name + " " + client.surname);

                    return(RedirectToAction("Index", "Home"));
                }
            }

            HttpContext.Session.SetInt32("AuthFailed", 1);

            return(RedirectToAction("Index", "Sign"));
        }