def logout(): authentication = AuthAPI(db).logout(next=None) if authentication['message'] == 'Logged out': return authentication else: error = ['{}'.format(k, v) for k, v in authentication['errors'].iteritems()][0] raise HTTP(400, error.replace('_', ' ').lower().capitalize())
def change_password(): old_password = request.vars.old_password new_password = request.vars.new_password new_password2 = request.vars.new_password2 authentication = AuthAPI(db).change_password(old_password=old_password, new_password=new_password, new_password2=new_password) if authentication['message'] == 'Password changed': return authentication else: error = ['{}'.format(v) for k, v in authentication['errors'].iteritems()][0] raise HTTP(400, error.replace('_', ' ').lower().capitalize())
def profile(): first_name = request.vars.first_name last_name = request.vars.last_name authentication = AuthAPI(db).profile(first_name=first_name, last_name=last_name) if authentication['message'] == 'Profile updated': avatar = 'https://www.gravatar.com/avatar/{}.jpg?s=200&d=mm'.format( hashlib.md5(auth.user.email).hexdigest()) authentication['user']['avatar'] = avatar return authentication else: error = ['{}'.format(v) for k, v in authentication['errors'].iteritems()][0] raise HTTP(400, error.replace('_', ' ').lower().capitalize())
def register(): first_name = request.vars.first_name last_name = request.vars.last_name email = request.vars.email password = request.vars.password authentication = AuthAPI(db).register(first_name=first_name, last_name=last_name, email=email, password=password, registration_key=None) if authentication['message'] == 'Registration successful': return authentication else: error = ['{}'.format(k, v) for k, v in authentication['errors'].iteritems()][0] raise HTTP(400, error.replace('_', ' ').lower().capitalize())
def login(): email = request.vars.email password = request.vars.password remember = request.vars.remember # remember_me = request.vars.remember authentication = AuthAPI(db).login(email=email, password=password) if authentication['message'] == 'Logged in': data = {'username': email, 'password': password, 'remember': remember} token_url = 'http://{}:{}/{}/api/token'.format( request.env.remote_addr, request.env.server_port, request.application) r = requests.post(token_url, data=data) if r.status_code == 200: # Get Token and contruct the header token = r.json()['token'] authentication['token'] = token return authentication else: raise HTTP(400, 'Cannot get token') else: error = ['{}'.format(v) for k, v in authentication['errors'].iteritems()][0] raise HTTP(400, error.replace('_', ' ').lower().capitalize())
def login(): email = request.vars.email password = request.vars.password # remember_me = request.vars.remember authentication = AuthAPI(db).login(email=email, password=password) if authentication['message'] == 'Logged in': data = {'username': email, 'password': password} r = requests.post('http://127.0.0.1:8000/api/token', data=data) print(r) if r.status_code == 200: # Get Token and contruct the header token = r.json()['token'] authentication['token'] = token return authentication else: authentication['token'] = None return authentication else: authentication['token'] = None return authentication
def logout(): authentication = AuthAPI(db).logout(next=None) return authentication