Beispiel #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);
        }
        protected override async void OnStart()
        {
            NavigationPage np;

            string loggedIn = await MyHelper.GetSavedValueForAppAsync("LoggedIn");

            if (loggedIn != null && loggedIn.Equals("true"))
            {
                try
                {
                    string user_info = await MyHelper.GetSavedValueForAppAsync("user_info");

                    deliveryMan = JsonConvert.DeserializeObject <Delivery_man>(user_info);

                    com.Execute(CheckAuthorizationToDeliver());

                    MainPage = new AppShell();
                }
                catch (Exception e)
                {
                    MyHelper.RemoveAllSavedValuesForApp();
                    np       = new NavigationPage(new SignInPage());
                    MainPage = np;
                }
            }
            else
            {
                np       = new NavigationPage(new SignInPage());
                MainPage = np;
            }
        }
        private async Task CheckAuthorizationToDeliver()
        {
            Delivery_man d1 = (Delivery_man)await myHttpClient.sendHttpGetAsyncObject <Delivery_man>(Constants.ApiGetDeliveryManById + "?id_delivery_man=" + App.deliveryMan.id_delivery_man);

            if (!d1.authorized)
            {
                MyHelper.RemoveAllSavedValuesForApp();

                NavigationPage np = new NavigationPage(new SignInPage());
                MainPage = np;
            }
        }
        public AuthenticationViewModel()
        {
            Title = "Sing In";

            SingInCommand = new Command(OnSingIn);
            SwitchToForgotPasswordCommand = new Command(OnSwitchToForgotPassword);

            user = new Delivery_man();

            user.firstname = "";
            user.lastname  = "";
            user.gender    = "";
            user.email     = "";
            user.password  = "";
            user.phone     = "";
            user.photo     = "";
            IsMale         = true;
        }
Beispiel #5
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);
        }
Beispiel #6
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);
        }
Beispiel #7
0
        public JObject DeliveryManSignIn([FromBody] Delivery_man delivery_Man)
        {
            FastFoodEntities db = new FastFoodEntities();

            JObject j;

            try
            {
                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.email == delivery_Man.email);

                j = new JObject();
                j.Add(new JProperty("API error", false));

                if (d1 != null)
                {
                    if (Crypto.VerifyHashedPassword(d1.password, delivery_Man.password))
                    {
                        if (d1.authorized)
                        {
                            j.Add(new JProperty("LoggedIn", true));
                            j.Add(new JProperty("Message", "Connected successfully."));


                            // 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()));

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


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


                            // add user info
                            d1.password = "";
                            j.Add("user_info", d1.toJObject());
                        }
                        else
                        {
                            j.Add(new JProperty("LoggedIn", false));
                            j.Add(new JProperty("Message", "You are not authorized to deliver."));
                        }
                    }
                    else
                    {
                        j.Add(new JProperty("LoggedIn", false));
                        j.Add(new JProperty("Message", "The information is incorrect."));
                    }
                }
                else
                {
                    j.Add(new JProperty("LoggedIn", false));
                    j.Add(new JProperty("Message", "The information is incorrect."));
                }

                return(j);
            }
            catch (Exception e)
            {
                j = new JObject();
                j.Add(new JProperty("API error", true));
                j.Add(new JProperty("Message", "There is a problem try again."));

                return(j);
            }
        }