Пример #1
0
        ///<summary>
        ///Changes the given httpContext user's password on db
        ///with parameters inside the httpContext.Request.Form
        ///</summary>
        public static string PasswordChange(PDKS.Context context, HttpContext httpContext)
        {
            string prev = httpContext.Request.Form["prevPwInput"];
            string new1 = httpContext.Request.Form["newPwInput"];
            string new2 = httpContext.Request.Form["newPwInput2"];

            if (new1 != new2)
            {
                return("respPWMatchErr");
            }

            User user = new User();

            try
            {
                user = (User)context.UserSet.Single(b => (b.Username == httpContext.User.FindFirst("UserName").Value));
            }
            catch (Exception e)
            {
                System.Console.WriteLine(e.Message);
                return("serverErr");
            }
            if (user.Password != Crypt.Encrypt(prev))
            {
                return("wrongPWErr");
            }
            if (new1.Length < 6)
            {
                return("shortPWErr");
            }
            user.Password = Crypt.Encrypt(new1);
            context.SaveChanges();
            return("pwSuccess");
        }
Пример #2
0
        ///<summary>
        ///Responses the user absency excuses.
        ///redirects to "admin", "requestsTable" pages
        ///Requires: reqSelect, button through request
        ///</summary>
        public void OnPost()
        {
            string reqSelect = HttpContext.Request.Form["reqSelect"];
            string Button    = HttpContext.Request.Form["button"];

            if (Button.Contains("Back"))
            {
                Response.Redirect("/admin", false);
            }
            else if (Button.Contains("Check"))
            {
                Response.Redirect("/requestsTable", false);
            }
            else
            {
                UserWorked obj;
                try
                {
                    obj = (UserWorked)_context.UserWorkedSet.Single(b => (b.Id == Int32.Parse(reqSelect)));
                }
                catch (Exception)
                {
                    OnGet();
                    State = "Response process failed.";
                    return;
                }
                if (Button.Contains("Accept"))
                {
                    obj.ReqApproved = 1;
                }
                else if (Button.Contains("Decline"))
                {
                    obj.ReqApproved = 0;
                }
                try
                {
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                    OnGet();
                    State = "Response process failed.";
                    return;
                }
                OnGet();
                State = "Responded succesfully.";
                return;
            }
        }
Пример #3
0
        ///<summary>
        ///Changes the shifts of a user
        ///redirects to "hoursTable", "admin" pages
        ///Requires: button, idSelect, shiftSelect
        /// through request
        ///</summary>
        public void OnPost()
        {
            string button = HttpContext.Request.Form["button"];

            if (button.Contains("Back"))
            {
                Response.Redirect("/admin", false);
                return;
            }
            else if (button.Contains("Check"))
            {
                Response.Redirect("/hoursTable", false);
                return;
            }
            else
            {
                string idSelect    = HttpContext.Request.Form["idSelect"];
                string shiftSelect = HttpContext.Request.Form["shiftSelect"];
                try
                {
                    var query =
                        from u in _context.UserSet
                        where u.Id == Int32.Parse(idSelect)
                        select u;
                    foreach (User u in query)
                    {
                        u.StandartWorkHoursId = Int32.Parse(shiftSelect);
                        OnGet();
                        State = "Success";
                        return;
                    }
                    _context.SaveChanges();
                }
                catch (Exception e)
                {
                    State = "Failed";
                    OnGet();
                    Console.WriteLine(e.Message);
                }
            }
        }
Пример #4
0
        ///<summary>
        ///Handles the remote->local sync buttons.
        ///does a mass sync to purge the unmatching user records locally or
        ///checks if the name of a user exists on remote server or
        ///adds user from remote db to local db with entered name
        ///Requires: requester; Optionally: name
        ///</summary>
        public ActionResult OnPostSync()
        {
            string resId   = "";
            string resName = "";
            User   user;

            if (HttpContext.Request.Form["requester"].Contains("mass"))
            {
                using (SqlConnection conn = new SqlConnection())
                {
                    var query =
                        from us in _context.UserSet
                        select us;
                    if (query.Count() == 0)
                    {
                        return(new JsonResult("No users on db."));
                    }
                    SqlCommand cmd = new SqlCommand();
                    cmd.CommandText = "select * from SMP_PERSONEL where PERSONNELNUMBER in(";
                    List <User> usersLocal = new List <User>();
                    foreach (User us in query)
                    {
                        usersLocal.Add(us);
                        cmd.CommandText += "'" + us.Username + "',";
                    }
                    cmd.CommandText  = cmd.CommandText.Substring(0, cmd.CommandText.Length - 1);
                    cmd.CommandText += ");";
                    string IzinDbPath = Configuration.GetSection("Connections:IzinMsSqlDB").Value;
                    conn.ConnectionString = IzinDbPath;
                    SqlDataReader reader;
                    System.Console.WriteLine(cmd.CommandText);
                    cmd.Connection = conn;
                    conn.Open();
                    reader = cmd.ExecuteReader();
                    string tmp = "";
                    while (reader.Read())
                    {
                        tmp += (string)reader.GetValue(0);
                    }
                    foreach (User u in usersLocal)
                    {
                        if (tmp.Contains(u.Username))
                        {
                            continue;
                        }
                        _context.Remove(u);
                    }
                }
            }
            else
            {
                Name = HttpContext.Request.Form["name"];
                try
                {
                    using (SqlConnection conn = new SqlConnection())
                    {
                        try
                        {
                            user = (User)_context.UserSet.Single(b => (b.Name == Name));
                            return(new JsonResult("User already exists in local db"));
                        }
                        catch (Exception e)
                        {
                            System.Console.WriteLine(e.Message);
                        }
                        string IzinDbPath = Configuration.GetSection("Connections:IzinMsSqlDB").Value;
                        conn.ConnectionString = IzinDbPath;
                        SqlCommand    cmd = new SqlCommand();
                        SqlDataReader reader;
                        if (("ĞŞÇİÜÖ").Contains(Name.First()))
                        {
                            /*UNSOLVED,worked around:
                             * where EMPLNAME like user.Name not working. */
                            cmd.CommandText = "select * from SMP_PERSONEL";
                        }
                        else
                        {
                            cmd.CommandText = "select * from SMP_PERSONEL where EMPLNAME like '" + Name.First() + "%'; ";
                        }
                        System.Console.WriteLine(cmd.CommandText);
                        cmd.Connection = conn;
                        conn.Open();
                        reader = cmd.ExecuteReader();
                        bool resIsEmpty = true;
                        while (reader.Read())
                        {
                            if (!((string)reader.GetValue(1)).Contains(Name))
                            {
                                continue;
                            }
                            resIsEmpty = false;
                            resId      = (string)reader.GetValue(0);
                            resName    = (string)reader.GetValue(1);
                        }
                        if (resIsEmpty)
                        {
                            return(new JsonResult("No such users at remote db"));
                        }
                    }
                }
                catch (Exception e)
                {
                    System.Console.WriteLine(e.Message);
                    return(new JsonResult("No data on repo."));
                }
            }
            if (HttpContext.Request.Form["requester"].Contains("checker"))
            {
                return(new JsonResult(resId + " - " + resName));
            }
            else if (!HttpContext.Request.Form["requester"].Contains("mass"))
            {
                try
                {
                    user = (User)_context.UserSet.Single(b => (b.Username == resId));
                    return(new JsonResult("User already exists in local db"));
                }
                catch (Exception e)
                {
                    System.Console.WriteLine(e.Message);
                }
                _context.UserSet.Add(new User
                {
                    Name                = resName,
                    Username            = resId,
                    Role                = 2,
                    DaysOff             = 15,
                    Password            = Crypt.Encrypt("sifre"),
                    StandartWorkHoursId = 1
                });
                _context.SaveChanges();
                user = (User)_context.UserSet.Single(b => (b.Name == resName));
                _context.AdminAuthorizationSet.Add(new AdminAuthorization
                {
                    Customize = false,
                    Requests  = false,
                    Authority = false,
                    UserId    = user.Id
                });
                _context.SaveChanges();
                return(new JsonResult("Added user successfully"));
            }
            else
            {
                return(new JsonResult("DONE"));
            }
        }
Пример #5
0
        ///<summary>
        ///Depending on the selections gives/takes authorizations
        ///from users. Requires: authCheckboxes1, authCheckboxes2,
        /// button, selection parameters through request
        ///</summary>
        public void OnPostAuth()
        {
            string Check1 = HttpContext.Request.Form["authCheckboxes1"];
            string Check2 = HttpContext.Request.Form["authCheckboxes2"];
            string Button = HttpContext.Request.Form["button"];

            if (Button.Contains("Back"))
            {
                Response.Redirect("/authTable", false);
                return;
            }
            int Id = 0;

            if (!Int32.TryParse(HttpContext.Request.Form["selection"], out Id))
            {
                OnGetFromTable();
                State = "Request Failed";
                return;
            }
            AdminAuthorization qA;

            try
            {
                qA = (AdminAuthorization)(from a in _context.AdminAuthorizationSet
                                          where a.Id == Id
                                          select a).First();
            }
            catch (Exception)
            {
                _context.AdminAuthorizationSet.Add(new AdminAuthorization {
                    UserId = Id, Customize = false, Requests = false, Authority = false
                });
                _context.SaveChanges();
                qA = (AdminAuthorization)(from a in _context.AdminAuthorizationSet
                                          where a.Id == Id
                                          select a).First();
            }
            User qU =
                (User)(from a in _context.UserSet
                       where a.Id == qA.UserId
                       select a).First();

            if (Button == "Authorize")
            {
                if (Check1 == "on")
                {
                    qA.Customize = true;
                    qU.Role      = 1;
                }
                if (Check2 == "on")
                {
                    qA.Requests = true;
                    qU.Role     = 1;
                }
            }
            else if (Button == "Revoke")
            {
                if (Check1 == "on")
                {
                    qA.Customize = false;
                    if (!qA.Requests)
                    {
                        qU.Role = 2;
                    }
                }
                if (Check2 == "on")
                {
                    qA.Requests = false;
                    if (!qA.Customize)
                    {
                        qU.Role = 2;
                    }
                }
            }
            try
            {
                _context.SaveChanges();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
            OnGetFromTable();
            State = "Success";
        }
Пример #6
0
        ///<summary>
        ///Updates the state of an absent day with the users excuse.
        ///Requires: excuseRadios, requestRadios, requestRadios, button
        ///, button through request
        ///</summary>
        public void OnPostSubmit()
        {
            string   excuseRadios  = HttpContext.Request.Form["excuseRadios"];
            string   requestRadios = HttpContext.Request.Form["requestRadios"];
            string   selection     = HttpContext.Request.Form["selection"];
            string   button        = HttpContext.Request.Form["button"];
            string   customExcuse;
            DateTime selectedDate = new DateTime();

            if (button.Contains("Back"))
            {
                Response.Redirect("/worked", false);
                return;
            }
            if (!DateTime.TryParse(selection.Substring(0, 10), out selectedDate))
            {
                OnGet();
                State = "Invalid date.";
                return;
            }
            Int32.TryParse(HttpContext.User.Identity.Name, out Id);
            customExcuse = HttpContext.Request.Form["customExcuse"];
            var query =
                from u in _context.UserWorkedSet
                where u.UserId == Id &&
                u.date == selectedDate
                select u;

            foreach (UserWorked u in query)
            {
                if (excuseRadios.Contains("option1"))
                {
                    u.Excuse = "I had been working at another company for Sampaş";
                }
                else if (excuseRadios.Contains("option2"))
                {
                    u.Excuse = "I was sick";
                }
                else if (excuseRadios.Contains("option3"))
                {
                    u.Excuse = "I had/have personal problems";
                }
                else
                {
                    u.Excuse = customExcuse;
                }
                if (requestRadios.Contains("option1"))
                {
                    u.Request = 0;
                }
                else
                {
                    u.Request = 1;
                }
                u.ReqApproved = 3;
            }
            try
            {
                _context.SaveChanges();
                OnGet();
                State = "Submitted Successfully.";
                return;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Пример #7
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());
            }
        }