9
votes

While I was building my app at the end I wanted to test all of my functionality but the main one stopped working...

My login form seems to not be able to get the user information from the form.

My login template :

<script type="text/x-handlebars" data-template-name="login">
    <form {{action "login" on=submit}}>
        <div>
        <div>
            <label>Domain</label>
        </div>
        <div>
            {{input type="text" value=domain placeholder="Domain"}}

        </div>
    </div>

    <div>
        <div>
            <label>Username</label>
        </div>
        <div>
            {{input value=username type="text" placeholder="Username"}}
        </div>
    </div>

    <div>
        <div>
            <label>Password</label>
        </div>
        <div>
            {{input value=password type="password" placeholder="Password"}}
        </div>
    </div>
    <button type="submit" {{bind-attr disabled="isProcessing"}}>Log in</button>
    </form>
</script>

And my loginController:

App.LoginController = Ember.ObjectController.extend({
    actions: {
        login: function() {
            var data = this.getProperties("domain", "username", "password");

            console.log(data);
        }
    }
});

My action 'login' is triggered but I have those error that I can't explain :

Assertion failed: Cannot delegate set('domain', g) to the 'content' property of object proxy <App.LoginController:ember330>: its 'content' is undefined.

Uncaught Error: Property set failed: object in path "domain" could not be found or was destroyed.

It was working at the beginning and I must say that I have no clue about what kind of problem is that.

[edit] This is my LoginController & my map :

App.Router.map(function() {
    this.route('login', { path: '/' });
    this.route('home');
});

App.LoginController = Ember.ObjectController.extend({
    loginFailed: false,
    isProcessing: false,
    isSlowConnection: false,
    timeout: null,

    actions: {
        isSession: function(transition) {
            var session = this;
            Ember.$
                .get(host + '/session', function(data) {
                    console.log('DEBUG: Session OK');
                    var log = data.user;
                    session.store.push('login', log);
                })
                .fail(function() {
                    console.log('DEBUG: Session FAIL');
                    transition.abort();
                    session.transitionToRoute('login');
                });
        },
        login: function() {
            this.setProperties({
                loginFailed: false,
                isProcessing: true
            });
            this.set("timeout", setTimeout(this.slowConnection.bind(this), 1));
            var data = this.getProperties("domain", "username", "password");

            console.log(data);
            this.getLoginInfo(data);
        }
    },
    slowConnection: function() {
        this.set('isSlowConnection', true);
    },
    reset: function() {
        clearTimeout(this.get("timeout"));
        this.setProperties({
            loginFailed: false,
            isSlowConnection: false,
            isProcessing: false
        });
    },
    getLoginInfo: function(data) {
        var login = this;
        Ember.$
        .post(host + '/login', data, function(data) {
            console.log('DEBUG: Login OK');
            login.reset();
            var test = data.session.user;
            login.store.push('login', test);
            login.transitionToRoute('home');
        })
        .fail(function() {
            login.reset();
            login.set('loginFailed', true);
            console.log('DEBUG: Login Failed')
        });
    }
});

I'm using the isSession function in every beforeModel for my other pages to verify if the session is still available and, if so, to push the login data back in the store to save it again.

2
Please include the test. - Kingpin2k
This error typically occurs because the content property of an ObjectController is null. Is there somewhere else in your code in which you set that controller's content? - sheldonbaker
I'm not sure to understand your question but, I'm only using those data in my LoginController. And also its the first page of my app... - SuperMarco

2 Answers

14
votes

You are extended Em.ObjectController for login controller. The default value for content of an ObjectController is null. You should define the content property to set values to content. Below code will work

App.LoginController = Ember.ObjectController.extend({
content: {},
actions: {
    login: function() {
        var data = this.getProperties("domain", "username", "password");

        console.log(data);
    }
}
});
1
votes

Your properties should be declared on the controller (if they're deferred to its model):

App.LoginController = Ember.ObjectController.extend({
    domain: null,
    username: null,
    password: null,
    actions: {
        login: function() {
            var data = this.getProperties("domain", "username", "password");

            console.log(data);
        }
    }
});