lundi 25 décembre 2017

Grails 3 - f:table - how to display property of related class

There is 2 simple classes:

class Entity{
Integer id
Status status
String type
}

class Status{
Integer id
String name
}

I just need to replace representation of "status" field in Entity list and edit - instead of my.appStage : 1 -> "normal" How to do it?




i want to know which ip is shown to the website i visit

I used to use Hide My Ass VPN Client on Virtual Machine and all works good, until i needed to run VPN only for specific websites/IPs only, so i downloaded OpenVPN 2.4 and made Batch Scripts to connect and disconnect from VPN Server automatically,

Now the problem is that i want to make sure that the target website i visit is really affected with the VPN, i tested this with ip website and shows the VPN IP but in the another website i cant know what the website sees.

TIA




Ext JS Format DATA to "DD-MM-YYYY"

Using ExtJS 4.2.3, I have FORM with textfield. I need to get value from store to the field. Having problems with my attempt to format data in the desired format. Asking for help with syntax to format data to DD-MM-YYYY

Data in source: /Date(1417986000000)/

After trying to get data by:

Form_window.query('textfield[name="DateField"]')[0].setValue(NewDATA_store.getAt(1).get('DateData'))

Result: Mon Dec 08 2014 00:00:00 GMT+0300 (RTZ 2 (winter))

Result what I need: 08.12.2014




Use Firebase in Web App via Phone Number Log in to Restrict Access to Site?

Firebase now provides an authentication method using the users phone. A user opens a web page, and the page initiates a SMS verification process. Firebase stores the users phone number (Identifier) and a randomly generated User UID. This is great if you want to validate phone numbers of your users, but not so great for restricting access to a whitelist of known phone numbers. Using Firebase phone auth and the very handy firebaseui-web library you receive an authorization when a phone number (ANY phone number) is validated via SMS message.

I guess I could perform a test in the browser client to see if the phone number (after SMS validation) is on the authorized whitelist via an API call to another server; If valid team member, redirect to the team directory site and to a "thanks anyway" site if not. I will say, performing that query in the client browser JavaScript seems like the wrong thing to do. It would be too easy to cheat it. Definitely not a good thing to do,

I'm hoping to use Firebase and phone SMS authorization to restrict a web page's access to a white list of authorized phone numbers. My use case is a group of people who need access to a simple web page showing the phone numbers of others in the group. We don't want that visible to the world, but it would be nice to have in a handy form (i.e. Look up web page, press the <a href="tel:1-408-555-5555">1-408-555-5555</a> phone number for quick, easy access on a mobile phone. We intend to make the page persistent via Progressive Web Application methods.

Any hints on how to proceed on using Firebase to restrict a webpage to a whitelist of users' phone numbers?

Note: I've seen this response that hints that it may be possible to use Cloud Function to restrict access to content but its not clear to me how that would work.




after use generate_password_hash(password), password sequencethe is not in database

i am studying flask web, and have some question

@auth.route('/register', methods=['GET', 'POST'])
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user=User(email=form.email.data,username=form.username.data, 
                  password_hash=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('you can now login')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html', form=form)


class User(UserMixin, db.Model): 
    __tablename__ = 'users'
    id = db.Column(db.Integer, primary_key=True)
    email = db.Column(db.Integer, unique=True, index=True)
    username = db.Column(db.String(64), unique=True, index=True)
    role_id = db.Column(db.Integer, db.ForeignKey('roles.id'))
    password_hash = db.Column(db.String(128))
    @property
    def password(self):
        raise AttributeError('password is not a readable attribute')

    @password.setter
    def password(self, password):
        self.password_hash = generate_password_hash(password)

    def verify_password(self, password):
        return check_password_hash(self.password_hash, password) 

    def __repr__(self):
        return '<user %r>' % self.username

register image

database image

When I enter the account password registration, the password is 16. but The password of the database is also 16, not the sequence of the password.

i can't understand




urllib.error.URLError: HTTP Error 403: Forbidden from urllib.request.urlopen

I'm trying to get ulr status via urllib.request.urlopen and in some cases it return urllib.error.URLError: HTTP Error 403: Forbidden howewer I can open this url from browser successfully. Is it possible to overcome this problem with urllib or better to use some other lib?

def urllib_status(url):
    REQUEST_TIMEOUT = 10

    if 'http' not in url:
        url = 'http://' + url

    try:
        response = urllib.request.urlopen(url, timeout=REQUEST_TIMEOUT)
        return response.status
    except urllib.error.URLError as e:
        print('url:'+url)
        print('urllib.error.URLError:', e)
        return -1
    except ssl.SSLError as e:
        print('url:'+url)
        print('ssl.SSLError:', e)
        return -1
    except socket.error as e:
        print('url:'+url)
        print("socket.error: ", e)
        return -1




Extjs Record.get from Store

Using ExtJS 4.2.3. I have FORM with combobox field and some values inside on choose, and some textfields. I need to get value from store and put it in textfields when user pick 1 of the value in combobox. Using documentForm_window.query('textfield[name="Textfield1"]')[0].setValue(record.get("cfo_name")) in listener of combobox field. But it doesn't work.

Example of code on ExtJS:

documentForm_window = Ext.create("Ext.window.Window", {
        title: (document_GUID == null) ? "[Create]" : "[Edit]",
        width: 500,
        modal: true,
        layout: "fit",
        items: [{
            xtype: "form",
            frame: true,
            waitMsgTarget: true,
            listeners: {
                afterrender: function (form) {
                    if (document_GUID != null) {
                        form.getForm().load({
                            url: Ext.state.Manager.get("MVC_url") + "/Document/Get",
                            method: "GET",
                            params: { document_GUID: document_GUID },
                            waitMsg: "[loading]",
                            timeout: 300,
                            failure: function (form, action) {
                                if (action.result) Ext.Msg.alert("[Error1]!", action.result.errorMessage);
                                else Ext.Msg.alert("[Error2]!", "[Error3]!");
                            }
                        });
                    }
                }
            },
            defaults: {
                anchor: "100%",
                msgTarget: "side",
                labelWidth: 145,
                allowBlank: false
            },
            items: [{
                xtype: "combo",
                name: "document_type",
                fieldLabel: "<b>[Type]<font color='Red'>*</font></b>",
                displayField: "document_type_name",
                valueField: "document_type",
                queryMode: "local",
                triggerAction: "all",
                editable: false,
                store: document_store,
                    listeners: {
                        select: function(combo, records) {
                            console.log(combo);
                            console.log(records);
                            if(!Ext.isArray(records)) records = [records];
                            Ext.each(records, function (record) {
                                if (record.get(combo.valueField) == 3) {
                                            documentForm_window.query('textfield[name="Textfield1"]')[0].setValue(record.get("cfo_name"));
                                            documentForm_window.query('textfield[name="Textfield2"]')[0].setValue(record.getData().cfo_manager);

                                  }
                          });
                     }
             },
            formBind: true,
            buttons: [{
                text: (document_GUID == null) ? "[Create]" : "[Edit]",
                handler: function () {
                    var action = (document_GUID == null) ? "Create" : "Edit";

                    var form = this.up("form").getForm();
                    if (form.isValid()) {
                        form.submit({
                            url: Ext.state.Manager.get("MVC_url") + "/Document/" + action,
                            params: { document_GUID: document_GUID, treasury_GUID: tree_value },
                            waitMsg: "[Loading...]",
                            success: function (form, action) {
                                documentForm_window.destroy();
                                OrderLines_store.load({
                                    scope: this,
                                    callback: function (records, operation, success) {
                                        documents_List.query('*[itemId="DATA1_grid"]')[0].selModel.select(curr_position);
                                    }
                                });
                            },
                            failure: function (form, action) {
                                if (action.result) Ext.Msg.alert("[Error1]!", action.result.msg);
                                else Ext.Msg.alert("[Error2]!", "[Error3]!");
                            }
                        });
                    }
                }
            }]
        }]
    }).show();
}

Example of storage. And it's code below the image. enter image description here

  //stores //   
     document_store = new Ext.data.ArrayStore({
        fields: ["document_type", "document_type_name"],
        data: [[0, "data1"], [1, "data2"], [2, "data3"]]   
    });



  OrderLines_store = new Ext.data.Store({
            model: "OrderLine_model",
            proxy: {
                url: Ext.state.Manager.get("MVC_url") + "/OrderLine/ListForDocuments",
                type: "ajax",
                reader: { root: "data" }
            },
            sorters: [{
                property: "orderLine_id",
                direction: "ASC"
            }],
            remoteFilter: true,
            filters: [{
                property: "order_GUID",
                value: [" = ''" + treasury_GUID + "''"]
            }],
            autoLoad: true
        });