Пример #1
0
        ///<summary>
        ///Default get handler:
        ///Authenticates the user, gets the language resource,
        ///passes the selected day to client,
        ///fills the "days" list and finally provides the page
        ///</summary>
        public void OnGet(string day = "")
        {
            string redirectionPath = Interconnector.Authenticator(HttpContext.User, EPage.excuse);

            if (redirectionPath != "")
            {
                Response.Redirect(redirectionPath, false);
            }
            Int32.TryParse(HttpContext.User.Identity.Name, out Id);
            lang = LangResource.GetLanguageJson("excuse", User.FindFirst("Language").Value);
            var query =
                from u in _context.UserWorkedSet
                where u.UserId == Id &&
                u.ReqApproved == 2 &&
                u.WorkedTime < 8
                select u;

            days = new List <string>();
            foreach (UserWorked u in query)
            {
                days.Add(u.date.ToString("yyyy.MM.dd") + " / " + u.date.DayOfWeek);
                try
                {
                    if (DateTime.Equals(u.date, DateTime.Parse(day)))
                    {
                        clickedIndex = days.Count - 1;
                    }
                }
                catch (Exception)
                {
                    System.Console.WriteLine("No day input");
                }
            }
        }
Пример #2
0
        ///<summary>
        ///Default post handler:
        ///Checks the validity of the request inputs,
        ///creates cookie for the current user and
        ///redirects accordingly
        ///</summary>
        public void OnPost(string inputUsername, string inputPassword)
        {
            if (inputUsername is null || inputPassword is null)
            {
                State = "Please enter your info";
                return;
            }
            while (inputUsername.Length < 6)
            {
                inputUsername = "******" + inputUsername;
            }
            if (inputUsername.Length == 6)
            {
                inputUsername = "******" + inputUsername;
            }
            string             AuthStr;
            User               user;
            AdminAuthorization auth;

            try
            {
                string encPw = Crypt.Encrypt(inputPassword);
                user = (User)_context.UserSet.Single(b => (b.Username == inputUsername) && (b.Password == encPw));
            }
            catch (Exception)
            {
                State = "Login failed.";
                return;
            }
            try
            {
                auth = (AdminAuthorization)_context.AdminAuthorizationSet.Single(b => (b.UserId == user.Id));
            }
            catch (Exception)
            {
                State = "Login failed.";
                return;
            }
            State   = "login success";
            AuthStr = (auth.Customize ? 1 : 0) + "" + (auth.Requests ? 1 : 0) + "" + (auth.Authority ? 1 : 0);
            Interconnector.CreateCookie(user, AuthStr, HttpContext, "EN");
            if (user.Role == 1)
            {
                Response.Redirect("/admin", false);
            }
            if (user.Role == 2)
            {
                Response.Redirect("/worked", false);
            }
            else
            {
                State = "Your account is inactive";
            }
        }
Пример #3
0
        ///<summary>
        ///Default get handler:
        ///Authenticates the user, gets the language resource
        ///and finally provides the page
        ///</summary>
        public void OnGet()
        {
            string redirectionPath = Interconnector.Authenticator(HttpContext.User, EPage.admin);

            if (redirectionPath != "")
            {
                Response.Redirect(redirectionPath, false);
                return;
            }
            Name = User.FindFirst("FullName").Value;
            lang = LangResource.GetLanguageJson("admin", User.FindFirst("Language").Value);
        }
Пример #4
0
        ///<summary>
        ///Handles the Logout and Language change requests.
        /// creates a new cookie with desired language or
        /// logs out the user and redirects to login page
        ///</summary>
        public async Task OnPostLogoutAsync()
        {
            string Button = HttpContext.Request.Form["button"];

            if (!Button.Contains("Logout"))
            {
                Interconnector.CreateCookie(User, HttpContext, Button);
                Response.Redirect("/admin", false);
                return;
            }
            await HttpContext.SignOutAsync(
                CookieAuthenticationDefaults.AuthenticationScheme);

            Response.Redirect("/login", false);
        }
Пример #5
0
        ///<summary>
        ///Default get handler:
        ///Authenticates the user, gets the language resource
        ///, fills the "reqs" list and finally provides the page
        ///</summary>
        public void OnGet()
        {
            string redirectionPath = Interconnector.Authenticator(HttpContext.User, EPage.authTable);

            if (redirectionPath != "")
            {
                Response.Redirect(redirectionPath, false);
            }
            lang = LangResource.GetLanguageJson("requestsTable", User.FindFirst("Language").Value);
            var obj = (from w in _context.UserWorkedSet
                       join u in _context.UserSet
                       on w.UserId equals u.Id
                       where w.ReqApproved == 3
                       select new
            {
                UserId = u.Id
                ,
                Id = w.Id
                ,
                Name = u.Name
                ,
                Excuse = w.Excuse
                ,
                Request = w.Request
                ,
                Day = w.date
            }).ToList();

            if (obj.Count == 0)
            {
                State = "No users found.";
            }
            reqs = new List <Data>();
            for (int i = 0; i < obj.Count; i++)
            {
                reqs.Add(new Data(obj[i].Id,
                                  obj[i].UserId,
                                  obj[i].Name,
                                  obj[i].Excuse,
                                  obj[i].Request,
                                  obj[i].Day.ToString().Substring(0, obj[i].Day.ToString().Length - 9)
                                  ));
            }
            ViewData["Table"] = reqs;
        }
Пример #6
0
        ///<summary>
        ///Default get handler:
        ///Authenticates the user, gets the language resource
        ///and finally provides the page
        ///</summary>
        public void OnGet()
        {
            string redirectionPath = Interconnector.Authenticator(HttpContext.User, EPage.login);

            if (redirectionPath != "")
            {
                Response.Redirect(redirectionPath, false);
            }
            lang = LangResource.GetLanguageJson("login", "EN");


            try
            {
                if (HttpContext.User.FindFirst("Role").Value == "3")
                {
                    State = "Your account is inactive";
                }
            }
            catch (Exception) { }
        }
Пример #7
0
        ///<summary>
        ///Default get handler:
        ///Authenticates the user, gets the language resource
        ///, fills the "users" list and finally provides the page
        ///</summary>
        public void OnGet()
        {
            string redirectionPath = Interconnector.Authenticator(HttpContext.User, EPage.authTable);

            if (redirectionPath != "")
            {
                Response.Redirect(redirectionPath, false);
            }
            lang = LangResource.GetLanguageJson("hoursTable", User.FindFirst("Language").Value);
            var obj = (from s in _context.StandartWorkhoursSet
                       join u in _context.UserSet
                       on s.Id equals u.StandartWorkHoursId
                       select new
            {
                Id = u.Id
                ,
                Name = u.Name
                ,
                StartHr = s.StartHr
                ,
                EndHr = s.EndHr
                ,
                BreakTime = s.BreakTime
            }).ToList();

            if (obj.Count == 0)
            {
                State = "No users found.";
            }
            users = new List <Data>();
            for (int i = 0; i < obj.Count; i++)
            {
                users.Add(new Data(obj[i].Id,
                                   obj[i].Name,
                                   obj[i].StartHr.ToString().Substring(10, obj[i].StartHr.ToString().Length - 10),
                                   obj[i].EndHr.ToString().Substring(10, obj[i].EndHr.ToString().Length - 10),
                                   obj[i].BreakTime
                                   ));
            }
            ViewData["Table"] = users;
        }
Пример #8
0
        ///<summary>
        ///Default get handler:
        ///Authenticates the user, gets the language resource
        ///, fills the "users" list and finally provides the page
        ///</summary>
        public void OnGet()
        {
            string redirectionPath = Interconnector.Authenticator(HttpContext.User, EPage.hoursChange);

            if (redirectionPath != "")
            {
                Response.Redirect(redirectionPath, false);
                return;
            }
            lang = LangResource.GetLanguageJson("hoursChange", User.FindFirst("Language").Value);
            var query =
                from u in _context.UserSet
                where u.Id != Int32.Parse(HttpContext.User.Identity.Name)
                select u;

            users = new Dictionary <int, string>();
            foreach (User u in query)
            {
                users[u.Id] = u.Name;
            }
        }
Пример #9
0
        ///<summary>
        ///Default get handler:
        ///Authenticates the user, gets the language resource,
        ///fills the "reqs" list and finally provides the page
        ///</summary>
        public void OnGet()
        {
            string redirectionPath = Interconnector.Authenticator(HttpContext.User, EPage.excuseStates);

            if (redirectionPath != "")
            {
                Response.Redirect(redirectionPath, false);
                return;
            }
            string name = User.FindFirst("FullName").Value;

            lang = LangResource.GetLanguageJson("excuseStates", User.FindFirst("Language").Value);
            var obj = (from w in _context.UserWorkedSet
                       where w.UserId == Int32.Parse(User.FindFirst(ClaimTypes.Name).Value) && w.WorkedTime < 8 && w.ReqApproved != 2
                       select new
            {
                Id = w.Id
                ,
                Excuse = w.Excuse
                ,
                Request = w.Request
                ,
                Response = w.ReqApproved
                ,
                Date = w.date
            }).ToList();

            reqs = new List <Data>();
            for (int i = 0; i < obj.Count; i++)
            {
                reqs.Add(new Data(User,
                                  obj[i].Id,
                                  obj[i].Excuse,
                                  obj[i].Request,
                                  obj[i].Response,
                                  obj[i].Date.ToString().Substring(0, obj[i].Date.ToString().Length - 9)
                                  ));
            }
            ViewData["Table"] = reqs;
        }
Пример #10
0
        ///<summary>
        ///Default get handler:
        ///Authenticates the user, gets the language resource,
        ///fills the "auths" list and finally provides the page
        ///</summary>
        public void OnGet()
        {
            string redirectionPath = Interconnector.Authenticator(HttpContext.User, EPage.authTable);

            if (redirectionPath != "")
            {
                Response.Redirect(redirectionPath, false);
            }
            lang = LangResource.GetLanguageJson("authTable", User.FindFirst("Language").Value);

            var obj = (from a in _context.AdminAuthorizationSet
                       join u in _context.UserSet
                       on a.UserId equals u.Id
                       select new
            {
                Id = a.Id
                ,
                Name = u.Name
                ,
                Customize = a.Customize
                ,
                Requests = a.Requests
                ,
                Authority = a.Authority
            }).ToList();

            if (obj.Count == 0)
            {
                Response.Redirect("/admin", false);
            }
            auths = new List <Data>();
            for (int i = 0; i < obj.Count; i++)
            {
                auths.Add(new Data(obj[i].Id, obj[i].Name, obj[i].Customize, obj[i].Requests, obj[i].Authority));
            }
            ViewData["Table"] = auths;
        }
Пример #11
0
        ///<summary>
        ///Default get handler:
        ///Authenticates the user, gets the language resource
        ///, fills the "users" list and finally provides the page
        ///</summary>
        public void OnGet()
        {
            string redirectionPath = Interconnector.Authenticator(HttpContext.User, EPage.requestRespond);

            if (redirectionPath != "")
            {
                Response.Redirect(redirectionPath, false);
                return;
            }
            lang = LangResource.GetLanguageJson("requestRespond", User.FindFirst("Language").Value);
            var obj = (from u in _context.UserSet
                       join w in _context.UserWorkedSet
                       on u.Id equals w.UserId
                       where u.Id != Int32.Parse(HttpContext.User.Identity.Name) &&
                       w.ReqApproved == 3
                       select new
            {
                UserId = u.Id
                ,
                Name = u.Name
                ,
                Id = w.Id
            }).ToList();

            users = new List <Data>();
            if (obj.Count == 0)
            {
                State = "No requests found.";
                return;
            }
            for (int i = 0; i < obj.Count; i++)
            {
                users.Add(new Data(obj[i].UserId, obj[i].Name, obj[i].Id));
            }
            ViewData["Table"] = users;
        }
Пример #12
0
 ///<summary>
 ///Calls the interconnector to change the
 /// password of the user accordingly
 ///Requires: prevPwInput, newPwInput, newPwInput2
 /// through request
 ///</summary>
 public ActionResult OnPostPWChange()
 {
     lang = LangResource.GetLanguageJson("admin", User.FindFirst("Language").Value);
     return(new JsonResult(lang[Interconnector.PasswordChange(_context, HttpContext)]));
 }
Пример #13
0
        ///<summary>
        ///Default get handler:
        ///Authenticates the user, gets the language resource,
        ///fills the "weeks" list and finally provides the page.
        ///weeks are filled by fetching and grouping the days
        ///by week of a year
        ///</summary>
        public void OnGet()
        {
            string redirectionPath = Interconnector.Authenticator(HttpContext.User, EPage.worked);

            if (redirectionPath != "")
            {
                Response.Redirect(redirectionPath, false);
                return;
            }
            if (HttpContext.User.FindFirst("Role").Value == "1")
            {
                UserIsAdmin = true;
            }
            int uId = 0;

            Int32.TryParse(HttpContext.User.Identity.Name, out uId);

            Name = User.FindFirst("FullName").Value;
            lang = LangResource.GetLanguageJson("worked", User.FindFirst("Language").Value);
            List <UserWorked> worked = null;

            try
            {
                worked = _context.UserWorkedSet.Where(b => (b.UserId == uId)).ToList() as List <UserWorked>;
                worked.Sort((x, y) => DateTime.Compare(x.date, y.date));
                var d1             = worked.First().date;
                var d2             = worked.Last().date;
                var currentCulture = CultureInfo.CurrentCulture;
                weeks = new Dictionary <int, Week>();
                for (var dt = d1; dt <= d2; dt = dt.AddDays(1))
                {
                    var weekNo = currentCulture.Calendar.GetWeekOfYear(
                        dt,
                        currentCulture.DateTimeFormat.CalendarWeekRule,
                        currentCulture.DateTimeFormat.FirstDayOfWeek);
                    if (dt.DayOfWeek == DayOfWeek.Saturday || dt.DayOfWeek == DayOfWeek.Sunday)
                    {
                        continue;
                    }
                    if (!weeks.Keys.Contains(weekNo))
                    {
                        weeks[weekNo]         = new Week();
                        weeks[weekNo].dates   = new Dictionary <DayOfWeek, DateTime>();
                        weeks[weekNo].days    = new Dictionary <DayOfWeek, int>();
                        weeks[weekNo].dayReqs = new Dictionary <DayOfWeek, EDayStates>();
                    }
                    if (null == worked.Find(x => x.date == dt))
                    {
                        var newWorked = new UserWorked {
                            WorkedTime = 0, date = dt, UserId = uId
                        };
                        _context.UserWorkedSet.Add(newWorked);
                        _context.SaveChanges();
                        weeks[weekNo].days[dt.DayOfWeek]    = 0;
                        weeks[weekNo].dayReqs[dt.DayOfWeek] = EDayStates.UserPending;
                    }
                    else
                    {
                        weeks[weekNo].days[dt.DayOfWeek]    = worked.Find(x => x.date == dt).WorkedTime;
                        weeks[weekNo].dayReqs[dt.DayOfWeek] = (EDayStates)worked.Find(x => x.date == dt).ReqApproved;
                    }
                    weeks[weekNo].dates[dt.DayOfWeek] = dt;
                    Console.WriteLine(weekNo + " : " + dt.DayOfWeek + " : " + dt + " : " + weeks[weekNo].days[dt.DayOfWeek] + " : " + weeks[weekNo].dayReqs[dt.DayOfWeek]);
                }
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e.Message);
                worked = new List <UserWorked>();
                worked.Add(new UserWorked());
            }
        }