Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /users/authenticate:
- # binds a127 app logic to a route
- x-swagger-router-controller: users
- post:
- tags:
- - Users
- summary: Authenticate a user either with credentials or facebook ID.
- description: ""
- operationId: authenticate
- parameters:
- - name: body
- in: body
- description: Contains user ID and GCM token
- required: true
- schema:
- $ref: "#/definitions/Authenticate"
- responses:
- "200":
- description: Success
- schema:
- # a pointer to a definition
- $ref: "#/definitions/UserResponse"
- "405":
- description: Invalid input
- "500":
- description: General error message
- 'use strict';
- var util = require('util');
- var database = require('./database');
- var sql = database.sql;
- var config = database.config;
- module.exports = {
- authenticate: authenticate
- };
- function authenticate(req, res) {
- var username = req.swagger.params.body.value.username;
- var password = req.swagger.params.body.value.password;
- var facebookId = req.swagger.params.body.value.facebookId;
- sql.connect(config).then(function() {
- // Query
- new sql.Request()
- .input('username', sql.NVarChar, username)
- .input('facebookId', sql.NVarChar, facebookId)
- .execute('UserAuthentication', function(err, recordsets, returnValue) {
- // ... error checks
- console.dir(recordsets[0]);
- res.json(recordsets[0]);
- });
- }).catch(function(err) {
- // ... error checks
- console.dir(err);
- });
- // this sends back a JSON response which is a single string
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement