def get(self): # code provided by github code = self.get_argument('code') post_args = { 'code': code, 'client_id': config.gh_id, 'client_secret': config.gh_secret } # request some shit from github http_client = httpclient.HTTPClient() try: response = json.loads( http_client.fetch(config.gh_ex_url, method='POST', body=urllib.parse.urlencode(post_args), headers={ 'Accept': 'application/json' }).body.decode('utf-8')) access_token = response['access_token'] user = github.get_user(access_token) # add to db if 'id' in user: users.update_user(user['id'], user['login'], access_token, user['avatar_url'], github.get_languages(access_token), user['updated_at']) self.set_secure_cookie('user', str(user['id'])) fetched_user = users.get_user(user['id']) print(fetched_user) self.redirect('/#/match') else: self.redirect('/#/error/login') except httpclient.HTTPError as e: # HTTPError is raised for non-200 responses; the response # can be found in e.response. print('Error', e) print(traceback.format_exc()) except Exception as e: # Other errors are possible, such as IOError. print('Error', e) print(traceback.format_exc())
def update_user_by_id(id): username = request.form.get('username') age = request.form.get('age') first_name = request.form.get('first_name') last_name = request.form.get('last_name') email = request.form.get('email') user = update_user(username, age, first_name, last_name, email, id) return redirect(url_for('get_user_by_id', id=id))
def save_user_head_image(file, user_id): save_result = save_upload_file(file, user_id, HEAD_IMAGE_SUBDIR) if save_result.response_code / 100 != 2: return save_result update_result = update_user( user_id, head_image_url=json.loads( save_result.response_message)['head_image_url']) if update_result.response_code / 100 != 2: return update_result return save_result
def edituser_page(): if session == {} or session["logged_in"] == False: return redirect(url_for("home_page")) data = select_a_user(session['userid']) form = CallUserAccount() if request.method == "POST" and form.validate_on_submit(): userdata = form.data["user"] update_user(userdata, session["userid"]) return redirect(url_for("profile_page")) elif request.method == "POST" and not form.validate_on_submit(): errs = [] for fieldName, errorMessages in form.errors.items(): errs.append(errorMessages) errjson = json.dumps(errs) return render_template("/users/edituseraccount.html", user=session, form=form, data = data, errors=errjson) else: if data["username"] != None: form.user["username"].data = data["username"] if data["securityanswer"] != None: form.user["securityAnswer"].data = data["securityanswer"] return render_template("/users/edituseraccount.html", user=session, form=form, data = data)
def step_impl(context, req): user_name = context.user_info['username'] del context.user_info['username'] user_id = users.search_with_username("/users?username=", user_name).json()[0]['id'] context.response = users.update_user(req, str(user_id), context.user_info)
def step_impl(context, req, user_id): context.response = users.update_user(req, str(user_id), context.user_info)