public override void OnAuthorization(System.Web.Http.Controllers.HttpActionContext actionContext)
        {
            base.OnAuthorization(actionContext);
            if (actionContext.Request.Headers.Authorization == null)
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
            }
            else
            {
                string   encodedString = actionContext.Request.Headers.Authorization.Parameter;
                string   decodedString = Encoding.UTF8.GetString(Convert.FromBase64String(encodedString));
                string[] arr           = decodedString.Split(new char[] { ':' });
                string   username      = arr[0];
                string   password      = arr[1];

                OfficerRepository urepo = new OfficerRepository();

                if (username == urepo.Get(username).Officer_Name&& password == urepo.Get(username).Officer_password)
                {
                    Thread.CurrentPrincipal = new GenericPrincipal(new GenericIdentity(username), null);
                }
                else
                {
                    actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
                }
            }
        }
        public ActionResult ConfirmChangePassword(string oldpass, string Pass, string cpass)
        {
            OfficerRepository orepo = new OfficerRepository();
            LoginRepository   lrepo = new LoginRepository();

            Officer of = orepo.Get(Convert.ToInt32(Session["OfficerID"]));

            Logininfo log = lrepo.Get(Session["OfficerName"].ToString());

            if (Session["Password"].ToString() == oldpass)
            {
                if (Pass != cpass)
                {
                    ViewData["Message"] = "Password Didn't match";
                }
                else
                {
                    of.Officer_password = Pass;
                    log.Login_Password  = Pass;

                    orepo.Update(of);
                    lrepo.Update(log);

                    ViewData["Message"] = "Password Updated Successfully";
                    Session["Officer"]  = of;
                    Session["Password"] = Pass;
                }
            }
            else
            {
                ViewData["Message"] = "Wrong Password";
            }

            return(View("Empty"));
        }
Beispiel #3
0
        public ActionResult ConfirmOfficer_Salary(int Officer_Id)
        {
            OfficerRepository brepo = new OfficerRepository();
            Officer           br    = brepo.Get(Officer_Id);
            DateTime          d     = DateTime.Now;

            if (d >= Convert.ToDateTime(br.Officer_LastPaymentDate).AddDays(30))
            {
                br.Officer_LastPaymentDate = d.ToString();
                br.Officer_TotalPayment   += br.Officer_Salary;
                br.Officer_Balance        += br.Officer_Salary;

                brepo.Update(br);
                ViewData["Message"] = "Salary Payment Successfull";
            }
            else
            {
                ViewData["Message"] = "To Early to Pay Salary";
            }

            return(View("Empty"));
        }