Advertisement
Guest User

Untitled

a guest
May 24th, 2016
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. /users/authenticate:
  2. # binds a127 app logic to a route
  3. x-swagger-router-controller: users
  4. post:
  5. tags:
  6. - Users
  7. summary: Authenticate a user either with credentials or facebook ID.
  8. description: ""
  9. operationId: authenticate
  10. parameters:
  11. - name: body
  12. in: body
  13. description: Contains user ID and GCM token
  14. required: true
  15. schema:
  16. $ref: "#/definitions/Authenticate"
  17. responses:
  18. "200":
  19. description: Success
  20. schema:
  21. # a pointer to a definition
  22. $ref: "#/definitions/UserResponse"
  23. "405":
  24. description: Invalid input
  25. "500":
  26. description: General error message
  27.  
  28.  
  29. 'use strict';
  30.  
  31. var util = require('util');
  32. var database = require('./database');
  33. var sql = database.sql;
  34. var config = database.config;
  35.  
  36. module.exports = {
  37. authenticate: authenticate
  38. };
  39.  
  40. function authenticate(req, res) {
  41. var username = req.swagger.params.body.value.username;
  42. var password = req.swagger.params.body.value.password;
  43. var facebookId = req.swagger.params.body.value.facebookId;
  44.  
  45. sql.connect(config).then(function() {
  46. // Query
  47.  
  48. new sql.Request()
  49. .input('username', sql.NVarChar, username)
  50. .input('facebookId', sql.NVarChar, facebookId)
  51. .execute('UserAuthentication', function(err, recordsets, returnValue) {
  52. // ... error checks
  53.  
  54. console.dir(recordsets[0]);
  55. res.json(recordsets[0]);
  56. });
  57.  
  58. }).catch(function(err) {
  59. // ... error checks
  60. console.dir(err);
  61. });
  62.  
  63. // this sends back a JSON response which is a single string
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement