Changeset 467


Ignore:
Timestamp:
06/26/13 15:24:09 (12 years ago)
Author:
hendrikvanantwerpen
Message:

Fixed authentication.

Location:
Dev/trunk/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • Dev/trunk/src/client/qed-client/index.js

    r466 r467  
    2121        Router.register(route);
    2222    });
    23     Router.startup();
    2423
    25     session.restore();
     24    session.restore().then(function(){
     25        Router.startup();
     26    });
    2627   
    2728});
  • Dev/trunk/src/client/qed-client/pages/templates/surveyRun.html

    r466 r467  
    4545            <div>
    4646                <div class="qedLabel">Export results</div>
    47                 <a target="_blank" href="/surveyRun/${surveyRunId}/csv" class="qedField">To CSV</a>
     47                <a target="_blank" href="/api/surveyRuns/${surveyRunId}/responses.csv" class="qedField">To CSV</a>
    4848            </div>
    4949        </fieldset>
  • Dev/trunk/src/server/app.js

    r466 r467  
    7575
    7676    // ensure we're authenticated on API calls
    77     app.use('/api', function(req,res,next){
     77    function ensureAuthenticated(req,res,next){
    7878        if (!req.user) {
    7979            return res.send(401,{error:"Login before accessing API."});
     
    8181            return next();
    8282        }
    83     });
     83    }
    8484   
    8585    app.get(
    8686        '/api/login',
     87        ensureAuthenticated,
    8788        returnUser);
    8889
    8990    app.post(
    90         '/api/logout', function(req,res){
     91        '/api/logout',
     92        ensureAuthenticated,
     93        function(req,res){
    9194            req.logout();
    9295            res.send(200,{});
    9396        });
    9497
    95     app.get('/api/surveyRun/:id/response/csv',
    96             function(req, res) {
    97                 var id = req.params.id;
    98                 // query CouchDB and build the CSV file
    99                 res.set({
    100                     'Content-Type': 'text/csv',
    101                     'Content-Disposition': 'attachment; filename=responses-'+id+'.csv'
    102                 });
    103                 res.send(200, "Response for surveyRun "+id);
     98    app.get(
     99        '/api/surveyRuns/:id/responses.csv',
     100        ensureAuthenticated,
     101        function(req, res) {
     102            var id = req.params.id;
     103            // query CouchDB and build the CSV file
     104            res.set({
     105                'Content-Type': 'text/csv',
     106                'Content-Disposition': 'attachment; filename=surveyRun-'+id+'-responses.csv'
    104107            });
     108            res.send(200, "Response for surveyRun "+id);
     109        });
    105110   
    106111    // forward to couch
     112    app.use('/api/data', ensureAuthenticated);
    107113    app.use('/api/data', proxy(settings.couchDbURL));
    108114
Note: See TracChangeset for help on using the changeset viewer.