/www/jssrc/blerg/Recovery.js
enyo.kind({
    name: "blerg.Recovery",
    components: [
        {tag: 'h2', content: "Reset Your Password"},
        {tag: 'form', onsubmit: 'submitRecovery', components: [
            {kind: 'onyx.InputDecorator', classes: "recovery", components: [
                {kind: 'onyx.Input', name: "newPassword", type: 'password'}
            ]},
            {kind: 'onyx.Button', content: "Set", onclick: "submitRecovery", classes: "recovery"}
        ]}
    ],
    statics: {
        locationDetect: function(l) {
            var m = l.hash.match(/^#\/recovery\//);
            if (m) {
                return {
                    kind: 'blerg.Recovery'
                };
            }
        }
    },
    create: function() {
        this.inherited(arguments);
        this.bubble('onSetTitle', {section: 'Reset Password'});
    },
    submitRecovery: function(inSender, inEvent) {
        var m = location.hash.match(new RegExp('^#/recovery/(.*)$'));
        if (!m) {
            alert('Validation failed');
            return;
        }

        var req = new enyo.Ajax({
            url: '/aux/recovery/validate',
            method: 'POST',
            postBody: {
                data: m[1],
                password: this.$.newPassword.getValue()
            }
        });

        req.response(this, function(inSender, inResponse) {
            if (inResponse.status == 'success') {
                alert('Password changed successfully');
                location = '/';
            } else {
                alert('Password change failed');
            }
        });

        req.error(this, function(inSender, inResponse) {
            alert('Password change failed');
        });

        req.go();
    }
});