如何创建复选框记住我

时间:2017-10-24 09:06:21

标签: angularjs node.js angular-cookies

如何在我的网站登录中为复选框记住我开发一个函数,并在后端添加一个函数?还是只是在前端?------------------------------------------- -------------------------------------------------- -------------------------------------------------- -------------------------------------------------- ----------------- 服务器/ app.js:

/**
 * Main application file
 */

'use strict';

import express from 'express';
import mongoose from 'mongoose';
mongoose.Promise = require('bluebird');
import config from './config/environment';
import http from 'http';
import seedDatabaseIfNeeded from './config/seed';

// Connect to MongoDB
mongoose.connect(config.mongo.uri, config.mongo.options);
mongoose.connection.on('error', function(err) {
  console.error(`MongoDB connection error: ${err}`);
  process.exit(-1); // eslint-disable-line no-process-exit
});

// Setup server
var app = express();
var server = http.createServer(app);
var socketio = require('socket.io')(server, {
  serveClient: config.env !== 'production',
  path: '/socket.io-client'
});
require('./config/socketio').default(socketio);
require('./config/express').default(app);
require('./routes').default(app);

var bodyParser = require('body-parser');
/*var fileUpload = require('express-fileupload');
app.use(fileUpload());

app.use('/uploads', express.static(__dirname + '/uploads'));

// configure the app to use bodyParser()*/
app.use(bodyParser.urlencoded({
  extended: true
}));
app.use(bodyParser.json());

// Start server
function startServer() {
  app.angularFullstack = server.listen(config.port, config.ip, function() {
    console.log('Express server listening on %d, in %s mode', config.port, app.get('env'));
  });
}

seedDatabaseIfNeeded();
setImmediate(startServer);

// Expose app
exports = module.exports = app;

的客户机/ login.controller.js:

'use strict';

export default class LoginController {
  user = {
    name: '',
    email: '',
    password: '',
    rememberme: ''
  };
  errors = {
    login: undefined
  };
  submitted = false;
  Auth;
  $location;
  $state;

  /*@ngInject*/
  constructor(Auth, $location, $state) {
    this.Auth = Auth;
    this.$location = $location;
    this.$state = $state;
  }

  login(form) {
    this.submitted = true;
    if(form.$valid) {
      this.Auth.login({
        email: this.user.email,
        password: this.user.password,
        rememberme: this.user.rememberme

      })
        .then(() => {
          // Logged in, redirect to home
          this.$location.path('/');
          this.$state.go('main');
        })
        .catch(err => {
          this.errors.login = err.message;
        });
    }
  }

}

0 个答案:

没有答案