def post(self): self.set_header('Content-Type', 'application/json') username = self.arguments.get(CommonKeys.USERNAME, None) password = self.arguments.get(CommonKeys.PASSWORD, None) uri = self.arguments.get(CommonKeys.URI, None) result = {} if uri: if self.get_current_user(): self._response_authorized() else: self._response_unauthorized() elif username and password: username = username.encode('utf-8') password = password.encode('utf-8') authenticated = authenticate_user(username, password) if authenticated: self.set_secure_cookie(CommonKeys.USER, username, secure=True) self._response_authorized() else: self._response_unauthorized() else: if not username: result[CommonKeys.USERNAME] = ['Username is required.'] if not password: result[CommonKeys.PASSWORD] = ['Password is required.'] self.set_status(400) self.write(json.dumps(result))
def post(self): oldpassword = self.get_argument('old-password', None) password = self.get_argument('password', None) result = { 'error': True, 'description': '{}'.format( 'User data is missing. Please provide username, current and new ' 'password.') } if password: username = self.current_user if authenticate_user(username, oldpassword): #change_user_password(str(username), str(password)) result = {'error': False, 'description': 'changed password'} else: result = {'error': True, 'description': 'invalid password'} self.set_header('Content-Type', 'application/json') self.write(json.dumps(result))
def post(self): username = self.arguments.get(ApiArguments.NAME, None) password = self.arguments.get(ApiArguments.PASSWORD, None) username = username.encode('utf-8') password = password.encode('utf-8') if username and password: authenticated = authenticate_user(username, password) if authenticated: self.set_secure_cookie(CommonKeys.USER, username) return else: self.set_status(403) self.write("Invalid username and/or password .") else: self.set_status(403) self.write("Invalid username and/or password .")
def post(self): oldpassword = self.get_argument('old-password', None) password = self.get_argument('password', None) result = {'error': True, 'description': '{}'.format( 'User data is missing. Please provide username, current and new ' 'password.' )} if password: username = self.current_user if authenticate_user(username, oldpassword): #change_user_password(str(username), str(password)) result = {'error': False, 'description': 'changed password'} else: result = {'error': True, 'description': 'invalid password'} self.set_header('Content-Type', 'application/json') self.write(json.dumps(result))