Exemplo n.º 1
0
        public bool SendLogin()
        {
            RequestLogin objSend		= new RequestLogin();
            Query Oquery			= new Query( this._Controller );

            try
            {
                objSend.UserNick = this._InputName;
                objSend.UserPass = this._InputPass;

                Oquery.RequestParameters = objSend;

                Oquery.SendRequestPOST();

                ResponseLogin obj = JsonConvert.DeserializeObject<ResponseLogin>( Oquery.ResponseContent );

                if( Oquery.ResponseStatusCode == HttpStatusCode.OK )
                {
                    this.setAppSettings( "UserName", obj.data.FullName );
                    this.setAppSettings( "UserType", obj.data.TypeUser );
                    this.setAppSettings( "UserPictureUrl", this.ConfigBaseUrl + obj.data.ImagePath );

                    this.AuthToken = Oquery.ResponseHeader[0].Value.ToString();

                    this._UserFullName  = obj.data.FullName;
                    this._UserType      = obj.data.TypeUser;
                    this._LocationImage = this.ConfigBaseUrl + obj.data.ImagePath;
                }
                else
                {
                    throw new Exception( obj.msg );
                }

                return true;
            }
            catch(Exception e)
            {
                this._msgExceptionLogin = e.Message;
                return false;
            }
        }
Exemplo n.º 2
0
        public bool SendLogin()
        {
            RequestLogin objSend	= new RequestLogin();
            Query oQuery			= new Query( this._Controller );

            try
            {
                objSend.UserNick = this._InputName;
                objSend.UserPass = this._InputPass;

                oQuery.RequestParameters = objSend;

                oQuery.SendRequestPOST();

                if ( oQuery.ResponseStatusCode == HttpStatusCode.InternalServerError )
                    throw new ArgumentNullException( "Existe un error en el servidor:\n" + this._msgExceptionLogin, "Error en el Servidor" );
                else if ( oQuery.ResponseStatusCode == HttpStatusCode.NotFound )
                    throw new ArgumentNullException( "No se encontro recurso al cual acceder", "Recurso no encontrado" );

                msgResponse resp = JsonConvert.DeserializeObject<msgResponse>( oQuery.ResponseContent );

                if ( oQuery.ResponseStatusCode == HttpStatusCode.BadRequest )
                    throw new InvalidOperationException( resp.message );

                LoginData obj = JsonConvert.DeserializeObject<LoginData>( resp.data );

                if ( obj.UserLevel != "0" && obj.UserLevel != "1" && obj.UserLevel != "2" )
                    throw new InvalidOperationException( "TU NIVEL DE ACCESO NO ESTA PERMITIDO PARA ESTE SISTEMA" );

                this.setAppSettings( "User", this.InputName );
                this.setAppSettings( "UserName", obj.FullName );
                this.setAppSettings( "UserType", obj.UserType );
                this.setAppSettings( "UserLevel", obj.UserLevel );
                this.setAppSettings( "UserPictureUrl", this.ConfigBaseUrl + obj.ImagePath );

                this.setAppSettings( "InstitutionName", obj.Institution.NameInstitution );
                this.setAppSettings( "InstitutionLogo", obj.Institution.LogoInstitution );
                this.setAppSettings( "BranchCode", obj.Institution.BranchCode.ToString() );
                this.setAppSettings( "BranchAddress", obj.Institution.BranchAddress );
                this.setAppSettings( "Remember_me", this.RememberMe.ToString() );

                this.AuthToken = obj.Token;
                this.AccessLevel = Convert.ToInt32( obj.UserLevel );

                return true;
            }
            catch(Exception e)
            {
                this._msgExceptionLogin = e.Message;
                return false;
            }
        }