コード例 #1
0
        public JObject PutChangeDeliveryManPassword([FromBody] Delivery_man dm)
        {
            FastFoodEntities db   = new FastFoodEntities();
            JObject          jRes = new JObject();

            DELIVERY_MAN D1 = db.DELIVERY_MAN.FirstOrDefault(d => d.id_delivery_man == dm.id_delivery_man);

            if (Crypto.VerifyHashedPassword(D1.password, dm.password))
            {
                try
                {
                    D1.password = Crypto.HashPassword(dm.confirmation_code);
                    db.SaveChanges();
                    jRes.Add(new JProperty("Error", false));
                }
                catch (Exception e)
                {
                    jRes.Add(new JProperty("Error", true));
                    jRes.Add(new JProperty("TitleMessage", "Message"));
                    jRes.Add(new JProperty("Message", "Connection failed."));
                }
            }
            else
            {
                jRes.Add(new JProperty("Error", true));
                jRes.Add(new JProperty("TitleMessage", "Message"));
                jRes.Add(new JProperty("Message", "The password is incorrect."));
            }

            return(jRes);
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (HttpContext.Current.Session == null || HttpContext.Current.Session["admin"] == null)
            {
                Response.Redirect("~/LoginP.aspx");
            }

            int id = 0;

            if (string.IsNullOrEmpty(Request.QueryString["id"]) || !Int32.TryParse(Request.QueryString["id"], out id))
            {
                Response.Redirect("~/DeliveryMenP.aspx");
            }

            dM = db.DELIVERY_MAN.FirstOrDefault(dm => dm.id_delivery_man == id);

            if (dM == null)
            {
                Response.Redirect("~/DeliveryMenP.aspx");
            }

            Page.Header.Title = string.Format("Fast food - {0} {1}", dM.firstname, dM.lastname);

            if (IsPostBack == false)
            {
                FirstNameTextBox.Text = dM.firstname;
                LastNameTextBox.Text  = dM.lastname;
                GenderRadioButtonList.SelectedValue = dM.gender;
                PhoneTextBox.Text     = dM.phone;
                EmailTextBox1.Text    = dM.email;
                PasswordTextBox1.Text = "";
                if (!string.IsNullOrEmpty(dM.photo))
                {
                    DeliveryManImage.ImageUrl = "~/pictures/delivery_men/" + dM.photo;
                }
                else
                {
                    DeliveryManImage.ImageUrl = "~/pictures/delivery_men/delivery_man.png";
                }

                switch (dM.transport)
                {
                case "car.png": TransportImage.ImageUrl = "~/pictures/app/car.png"; break;

                case "moto.png": TransportImage.ImageUrl = "~/pictures/app/moto.png"; break;

                default: TransportImage.ImageUrl = "~/pictures/app/unknown.png"; break;
                }

                MatriculeTextBox.Text = dM.matricule;

                AuthorizedCheckBox.Checked = dM.authorized;
            }
        }
コード例 #3
0
        protected void AddButton_Click(object sender, EventArgs e)
        {
            DELIVERY_MAN dM = new DELIVERY_MAN();

            dM.firstname  = FirstNameTextBox.Text.Trim();
            dM.lastname   = LastNameTextBox.Text.Trim();
            dM.gender     = GenderRadioButtonList.SelectedValue;
            dM.phone      = PhoneTextBox.Text.Trim();
            dM.email      = EmailTextBox1.Text.Trim();
            dM.password   = Crypto.HashPassword(PasswordTextBox1.Text);
            dM.photo      = "delivery_man.png";
            dM.authorized = true;
            dM.id_admin   = ((TADMIN)HttpContext.Current.Session["admin"]).id_admin;

            db.DELIVERY_MAN.Add(dM);
            db.SaveChanges();

            FirstNameTextBox.Text = "";
            LastNameTextBox.Text  = "";
            GenderRadioButtonList.ClearSelection();
            PhoneTextBox.Text     = "";
            EmailTextBox1.Text    = "";
            PasswordTextBox1.Text = "";
        }
コード例 #4
0
        public JObject PutChangeDeliveryManTransport([FromBody] Delivery_man dm)
        {
            FastFoodEntities db   = new FastFoodEntities();
            JObject          jRes = new JObject();

            DELIVERY_MAN D1 = db.DELIVERY_MAN.FirstOrDefault(d => d.id_delivery_man == dm.id_delivery_man);

            try
            {
                D1.transport = dm.transport;
                D1.matricule = dm.matricule;
                db.SaveChanges();

                jRes.Add(new JProperty("Error", false));
            }
            catch (Exception e)
            {
                jRes.Add(new JProperty("Error", true));
                jRes.Add(new JProperty("TitleMessage", "Message"));
                jRes.Add(new JProperty("Message", "Connection failed."));
            }

            return(jRes);
        }
コード例 #5
0
        public JObject PutChangeDeliveryManInfo([FromBody] Delivery_man dm)
        {
            FastFoodEntities db   = new FastFoodEntities();
            JObject          jRes = new JObject();

            DELIVERY_MAN D1 = db.DELIVERY_MAN.FirstOrDefault(d => d.id_delivery_man == dm.id_delivery_man);
            DELIVERY_MAN D2 = db.DELIVERY_MAN.FirstOrDefault(d => d.email == dm.email && d.id_delivery_man != dm.id_delivery_man);

            if (D2 != null && D2.email == dm.email)
            {
                jRes.Add(new JProperty("Error", true));
                jRes.Add(new JProperty("TitleMessage", "Change the email address"));
                jRes.Add(new JProperty("Message", "This email address is in use by another account."));
            }
            else if (Crypto.VerifyHashedPassword(D1.password, dm.password))
            {
                jRes.Add(new JProperty("Error", false));

                D1.firstname = dm.firstname;
                D1.lastname  = dm.lastname;
                D1.gender    = dm.gender;
                D1.email     = dm.email;
                D1.phone     = dm.phone;

                db.SaveChanges();

                Delivery_man d1 = db.DELIVERY_MAN.Select(d => new Delivery_man()
                {
                    id_delivery_man = d.id_delivery_man,
                    firstname       = d.firstname,
                    lastname        = d.lastname,
                    gender          = d.gender,
                    email           = d.email,
                    password        = d.password,
                    phone           = d.phone,
                    photo           = d.photo,
                    transport       = d.transport,
                    matricule       = d.matricule,
                    latitude        = d.latitude,
                    longitude       = d.latitude,
                    authorized      = d.authorized,
                    state           = d.state,
                    id_admin        = d.id_admin
                }).FirstOrDefault(d => d.id_delivery_man == D1.id_delivery_man);


                // add JWT
                List <Claim> listClaims = new List <Claim>();
                listClaims.Add(new Claim("user_type", "Delivery man"));
                listClaims.Add(new Claim("id_delivery_man", d1.id_delivery_man.ToString()));

                jRes.Add(new JProperty("JWT", MyJWT.GenerateJWT(listClaims)));


                // add id_user
                jRes.Add(new JProperty("id_delivery_man", d1.id_delivery_man.ToString()));


                // add user info
                d1.password = "";
                jRes.Add("user_info", d1.toJObject());
            }
            else
            {
                jRes.Add(new JProperty("Error", true));
                jRes.Add(new JProperty("TitleMessage", "Message"));
                jRes.Add(new JProperty("Message", "The password is incorrect."));
            }

            return(jRes);
        }