~osclone-developers/flubtitles/alpha

« back to all changes in this revision

Viewing changes to api/auth.py

  • Committer: swick at 2flub
  • Date: 2011-02-22 15:12:51 UTC
  • Revision ID: swick@2flub.org-20110222151251-nsjsh0yrn1nolqa2
Moving to REST

Show diffs side-by-side

added added

removed removed

Lines of Context:
88
88
        else:
89
89
            return "Sorry, ging net"
90
90
 
91
 
    def LogIn(self, email="", password="", useragent=""):
92
 
        self.profiler.mark()
93
 
        reply = {}
94
 
 
95
 
        self.mailaddress = email.lower()
96
 
 
97
 
        if useragent in self.useragents:
98
 
            # if username and password empty, just return token and write anonymous as user_id in Session Doc
99
 
            # if username and password given, check password and if OK, write email as user_id in Session Doc
100
 
            if self.mailaddress == "" and password == "":
101
 
                self.email = 'anonymous@flubtitles.org'
102
 
                token = self.auth.create_session(self.email)
103
 
                reply['statusCode']      = "200"
104
 
                reply['statusText']      = statuscodes.statuscodes['200']
105
 
                reply['token']           = token
106
 
                reply['time']            = self.profiler.elapsed()
107
 
 
108
 
            elif self.auth.is_authenticated(self.mailaddress, password):
109
 
                self.email = self.mailaddress
110
 
                token = self.auth.create_session(self.email)
111
 
                reply['statusCode']      = "200"
112
 
                reply['statusText']      = statuscodes.statuscodes['200']
113
 
                reply['token']           = token
114
 
                reply['time']            = self.profiler.elapsed()
115
 
            else:
116
 
                reply['statusCode']  = "401"
117
 
                reply['statusText']  = statuscodes.statuscodes['401']
118
 
                reply['time']        = self.profiler.elapsed()
119
 
        else:
120
 
            reply['statusCode']     = "411"
121
 
            reply['statusText']     = statuscodes.statuscodes['411']
122
 
            reply['time']           = self.profiler.elapsed()
123
 
        return reply
124
 
 
125
 
    def LogOut(self, token):
126
 
        """Logout and remove token from database"""
127
 
 
128
 
        self.profiler.mark()
129
 
        reply = {}
130
 
        if self.auth.session_exists(token):
131
 
            logger.log.info('Trying to logout')
132
 
            self.auth.delete_session(token)
133
 
            reply['statusCode']     = "200"
134
 
            reply['statusText']     = statuscodes.statuscodes['200']
135
 
            reply['time']           = self.profiler.elapsed()
136
 
        else:
137
 
            reply['statusCode']     = "406"
138
 
            reply['statusText']     = statuscodes.statuscodes['406']
139
 
            reply['time']           = self.profiler.elapsed()
140
 
        return reply
141
 
 
142
91
    def ResetPassword(self, useragent, email, password):
143
92
 
144
93
        self.profiler.mark()