public JsonResult Index()
        {
            ConvertibleHashtable h  = ConvertibleHashtable.fromRequest();
            ConvertibleHashtable ud = ConvertibleHashtable.fromJObject((JObject)h["user_data"]);
            ApiKey k = ApiKey.getApiKey();

            if (k.isAdmin())
            {
                if (h["type"].ToString() == "supplier")
                {
                    ud.merge(((JObject)h["supplier_data"]).ToObject <ConvertibleHashtable>());
                    if (ud.ContainsKey("user_id"))
                    {
                        ud.Remove("user_id");
                    }
                    ud.toObject <Supplier>().insert();
                }
                else if (h["type"].ToString() == "admin")
                {
                    ud.toObject <Admin>().insert();
                }
                else
                {
                    return(Json(Costants.WRONG_USER_TYPE, JsonRequestBehavior.AllowGet));
                }
                return(Json(Costants.OK, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(Costants.UNAUTHORIZED, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #2
0
        /// Restituisce true <=> l'email e la password corrispondono a un utente esistente
        public static bool checkPassword(String email, String password)
        {
            bool x = false;
            ConvertibleHashtable h = getUserHashtableByEmail(email);

            if (h.ContainsKey("password"))
            {
                x = h["password"].ToString() == password;
            }

            return(x);
        }
        public JsonResult Update(int id)
        {
            ConvertibleHashtable h = ConvertibleHashtable.fromRequest();
            ApiKey k = ApiKey.getApiKey();

            if (k.isAdmin() || k.checkUser(id))
            {
                // controlla se si deve modificare le informazioni specifiche di un supplier
                ConvertibleHashtable supplierCurrentData = Supplier.getHashtableByUserId(id);
                if (h.ContainsKey("supplier_data") && supplierCurrentData["user_id"].ToString() == id.ToString())
                {
                    ConvertibleHashtable newData = ConvertibleHashtable.fromJObject((JObject)h["supplier_data"]);
                    if (h.ContainsKey("user_data"))
                    {
                        newData.merge(ConvertibleHashtable.fromJObject((JObject)h["user_data"]));
                    }
                    supplierCurrentData.update(newData);
                    if (!supplierCurrentData.ContainsKey("user_id"))
                    {
                        supplierCurrentData.Add("user_id", id);
                    }
                    supplierCurrentData.toObject <Supplier>().update();
                }
                // modifica le info di base dell'utente, che sia admin o supplier
                else
                {
                    ConvertibleHashtable currentData = Model.getHashtableById <User>(id);
                    ConvertibleHashtable newData     = ConvertibleHashtable.fromJObject((JObject)h["user_data"]);
                    currentData.update(newData);
                    currentData.toObject <User>().update();
                }
                // aggiorna le api key per riflettere evenutali modifiche alla password o alla mail
                ApiKey.fromUserId(id).update();
                return(Json(Costants.OK, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(Costants.UNAUTHORIZED, JsonRequestBehavior.AllowGet));
            }
        }
Exemple #4
0
        public JsonResult Index()
        {
            ApiKey k = ApiKey.getApiKey();
            ConvertibleHashtable data = ConvertibleHashtable.fromRequest();

            if (k.isAdmin() || (data.ContainsKey("supplier_id") &&
                                Supplier.checkUserId(k.user_id, int.Parse(data["supplier_id"].ToString()))))
            {
                ConvertibleHashtable.fromRequest().toObject <Product>().insert();
                return(Json(Costants.OK, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(Costants.UNAUTHORIZED, JsonRequestBehavior.AllowGet));
            }
        }