Merhaba Kullanıcının yeni bir hesap oluşturabildiği, giriş yapabildiği ve hesabıyla ilgili bilgileri ve yalnızca yetkilendirildiği zaman korunan bazı yolları görebildiği Ember ve Firebase'i kullanarak bir uygulama yapıyorum. Bu nedenle, yetkili olmayan kullanıcılar yalnızca 2 yolu görebilirler: giriş formunu görüntüleyen ve görüntülenen ve yeni bir hesap oluşturmasına olanak tanıyan kayıt rotası ('/ signup') bağlantısını gösteren indeks ('/').Kullanıcı yetkilendirmesinden sonra dizin/dizin yolu modeli kancası nasıl çağırılır?
Router.map(function() {
this.route('signup');
this.route('index', {path: '/'}, function() {
this.authenticatedRoute('index', {path: '/'});
this.authenticatedRoute('events');
this.authenticatedRoute('about');
});
});
app/templates/index.hbs giriş formu içerir ve iç içe endeks rotada kullanıcı günlükleri oluşturulur ancak modelin kanca olduğunda çağrılır değil bunun sonu: My app/router.js Yönlendirici şöyle yenilenir. Nasıl çalıştırılır?
app/templates/index.hbs
{{#unless session.isAuthenticated}}
{{signin-form store=store session=session authorized="authorized"}}
{{else}}
{{#link-to 'index.index' class="item"}}Home{{/link-to}}
{{#link-to 'index.events' class="item"}}Events{{/link-to}}
{{#link-to 'index.about' class="item"}}About{{/link-to}}
{{outlet}}
{{/unless}}
uygulama/rotalar/
import Ember from 'ember';
export default Ember.Route.extend({
beforeModel() {
return this.get("session").fetch().catch(function() {});
},
actions: {
signOut() {
this.get('session').close();
this.transitionTo('index');
},
accessDenied() {
this.transitionTo('index');
},
authorized() {
console.log('authorized');
this.transitionTo('index');
}
}
});
app/bileşenleri/signin-form.js ise
import Ember from 'ember';
export default Ember.Component.extend({
didRender() {
this._super(...arguments);
this.$('form.ui.form').form();
},
signIn() {
let { userPassword, userEmail }
= this.getProperties('userPassword', 'userEmail');
console.log('Logging with', userPassword, userEmail);
this.get("session").open("firebase", {
provider: 'password',
email: userEmail,
password: userPassword
}).then((data) => {
console.log(data);
this.sendAction('authorized');
});
},
actions: {
submit() {
this.signIn();
}
}
});
Oturum açmak için ayrı bir rota kullanmanız ve kullanıcıyı bu rotaya yönlendirmek için bir beforeModel kanca kullanmanız önerilir. Nasıl görünüyorsun, ne kadar basit çalışıyor? – Lux