Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $(() => {
- const app = Sammy('#container', function () {
- this.use('Handlebars', 'hbs');
- this.get('#/home', getWelcomePage);
- this.get('index.html', getWelcomePage);
- this.post('#/register', (ctx) => {
- //console.log('lol');
- let username = ctx.params.username;
- let password = ctx.params.password;
- let repeatPass = ctx.params.passwordRepeat;
- if (repeatPass !== password) {
- notify.showError('Passwords should match!')
- }
- else {
- auth.register(username, password).then((userData) => {
- auth.saveSession(userData);
- notify.showInfo("user registration successful");
- ctx.redirect('#/home');
- })
- .catch(notify.handle);
- }
- });
- this.post('#/login', (ctx) => {
- let username = ctx.params['username-login'];
- let password = ctx.params['password-login'];
- if (password === "") {
- notify.showError('Password field should not be empty!')
- }
- else if (username ===""){
- notify.showError('Username field should not be empty!')
- }
- else {
- auth.login(username, password)
- .then((userData) => {
- auth.saveSession(userData);
- notify.showInfo('Login successful.');
- console.log("lol");
- ctx.loadPartials({
- header:"./templates/common/header.hbs",
- tableFootForm:"./templates/forms/tableFootForm.hbs",
- createEntyForm:"./templates/forms/createEntryForm.hbs",
- }).then(
- function(){
- this.partial("./templates/pages/nonAnnonymousPage.hbs");
- }
- )
- })
- .catch(notify.handleError);
- }
- });
- function getWelcomePage(ctx){
- if(!auth.isAuth()){
- ctx.loadPartials({
- header:"./templates/common/header.hbs",
- footer:"./templates/common/footer.hbs",
- loginForm:"./templates/forms/loginForm.hbs",
- registerForm:"./templates/forms/registerForm.hbs",
- }).then(function(){
- this.partial('./templates/welcome-anonymous.hbs');
- })
- }
- else{
- ctx.redirect('#/home');
- }
- }
- this.get()
- function getHome(ctx){
- }
- });
- app.run();
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement