Ejemplo n.º 1
0
        public HttpResponseMessage PutTunnel(Spartan_User emp, string user, string password)
        {
            var client = new System.Net.WebClient();

            client.Headers = TokenManager.GetAuthenticationHeader(user, password);
            client.Headers["Content-Type"] = "application/json";
            var dataString = new JavaScriptSerializer().Serialize(emp);

            var result = client.UploadString(new Uri(baseApi + ApiControllerUrl + "/Put?Id=" + emp.Id_User), "PUT"
                                             , dataString);

            return(Request.CreateResponse(HttpStatusCode.OK, result, Configuration.Formatters.JsonFormatter));
        }
Ejemplo n.º 2
0
        public HttpResponseMessage Delete(int id)
        {
            Spartan_User varSpartan_User = this.service.GetByKey(id, false);
            bool         result          = false;

            if (varSpartan_User == null)
            {
                return(Request.CreateResponse(HttpStatusCode.NotFound));
            }

            try
            {
                result = this.service.Delete(id);//, globalData, dataReference);
            }
            catch (ServiceException ex)
            {
                return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
            }

            return(Request.CreateResponse(HttpStatusCode.OK, result));
        }
Ejemplo n.º 3
0
        public HttpResponseMessage Post(Spartan_User varSpartan_User)
        {
            if (ModelState.IsValid)
            {
                var data = "-1";
                try
                {
                    data = Convert.ToString(this.service.Insert(varSpartan_User));
                }
                catch (ServiceException ex)
                {
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, ex.Message));
                }

                return(Request.CreateResponse(HttpStatusCode.OK, data, Configuration.Formatters.JsonFormatter));
            }
            else
            {
                var errors = ModelState.Values.SelectMany(v => v.Errors).Select(error => error.ErrorMessage);
                return(Request.CreateResponse(HttpStatusCode.BadRequest, errors));
            }
        }
Ejemplo n.º 4
0
        public ActionResult ChangePassword(Spartan_User spartan_user)
        {
            if (!_tokenManager.GenerateToken())
            {
                return(Json(null, JsonRequestBehavior.AllowGet));
            }
            int userId = Convert.ToInt32(Session["USERID"]);

            _ISpartan_UserApiConsumer.SetAuthHeader(_tokenManager.Token);
            _ISpartan_ChangePasswordAutorizationApiConsumer.SetAuthHeader(_tokenManager.Token);
            var user = _ISpartan_UserApiConsumer.GetByKey(userId, false).Resource;

            if (Session["EstatusChangePassword"].ToString() == "0" || Session["EstatusChangePassword"].ToString() == "4")
            {
                Spartan_ChangePasswordAutorization newChange = new Spartan_ChangePasswordAutorization();
                newChange.Estatus           = 1;
                newChange.Fecha_de_Registro = DateTime.Now;
                newChange.Hora_de_Registro  = DateTime.Now.Hour.ToString() + ":" + DateTime.Now.Minute.ToString();
                newChange.Usuario           = userId;
                newChange.Email             = user.Email;

                var result = _ISpartan_ChangePasswordAutorizationApiConsumer.Insert(newChange, null, null).Resource;

                //SEND EMAIL TO ADMIN
                var           usersAdmin = _ISpartan_UserApiConsumer.ListaSelAll(0, 10, "Spartan_User.Role = 1", "").Resource;
                List <string> to         = new List <string>();
                if (usersAdmin.RowCount > 0)
                {
                    foreach (var userAdmin in usersAdmin.Spartan_Users)
                    {
                        to.Add(userAdmin.Email);
                    }
                    Helper.SendEmail(to, "Pedido de cambio de Password", "El usuario " + user.Name + " con ID=" + user.Id_User + " ha solicitado cambio de password.");
                }
            }
            else
            {
                _ISpartan_UserApiConsumer.SetAuthHeader(_tokenManager.Token);
                _ISpartan_User_Historical_PasswordApiConsumer.SetAuthHeader(_tokenManager.Token);

                var model = _ISpartan_UserApiConsumer.GetByKey(spartan_user.Id_User, false).Resource;
                model.Password = EncryptHelper.CalculateMD5Hash(spartan_user.Password);
                _ISpartan_UserApiConsumer.Update(model, null, null);
                _ISpartan_SettingsApiConsumer.SetAuthHeader(_tokenManager.Token);
                var      ExpirationDaysDB  = _ISpartan_SettingsApiConsumer.GetByKey("ExpirationDays", false).Resource;
                int      ExpirationDays    = Convert.ToInt32(ExpirationDaysDB.Valor);
                DateTime newDateExpiracion = DateTime.Now.AddDays(ExpirationDays);
                var      fechaJSON         = _ISpartaneQueryApiConsumer.ExecuteRawQuery("UPDATE Spartan_User SET Fecha_de_Expiracion = '" + newDateExpiracion.ToString("yyyy-MM-dd") + "' where Id_User="******"Spartan_ChangePasswordAutorization.Estatus=2", "").Resource;
                if (changes.RowCount > 0)
                {
                    var lastChange = changes.Spartan_ChangePasswordAutorizations.First();
                    lastChange.Estatus = 4;
                    var result = _ISpartan_ChangePasswordAutorizationApiConsumer.Update(lastChange, null, null).Resource;
                }

                //ADD TO HISTORICAL
                Spartan_User_Historical_Password newData = new Spartan_User_Historical_Password();
                newData.Fecha_de_Registro = DateTime.Now;
                newData.Password          = EncryptHelper.CalculateMD5Hash(spartan_user.Password);
                newData.Usuario           = spartan_user.Id_User;
                var resultInsert = _ISpartan_User_Historical_PasswordApiConsumer.Insert(newData, null, null).Resource;
            }
            return(Redirect("~/"));
        }