def github_callback(oauth_token): if oauth_token is None: flash('Authorization failed.') return redirect(url_for('index')) g.github_token = oauth_token github_id = github.get('user')['id'] user = User.search(github_id=github_id) if user is None: user = User(github_id=github_id) user.save() login_user(user) return redirect(request.args.get('next') or url_for('dashboard'))
def updateUploads(self): req = ("add new archive to uploads/ on the website? " "(warning: checksums will change if it already exists)") if User.yesNo(req, defaultToYes=True) is False: return False if check_call(shlex.split("./docs/build-uploads.sh")) != 0: return exit(5) return True
def createImportBranch(self, version): branchName = "import-v{}".format(version) Git.chdirToRepositoryTopLevel() if not goTo("website"): User.pause() return Git.checkout(branchName, create=True) Git.add('.') Git.commit("update for offlineimap v{}".format(version)) User.pause( "website: branch '{}' is ready for a merge in master!".format( branchName)) goTo('..') return branchName
def deleteTester(self, number): self.listTesters() removed = self.feedbacks.pop(number) self.testers.remove(removed) print("New list:") self.feedbacks = None self.listTesters() print("Removed: {}".format(removed)) ans = User.request("Save on disk? (s/Q)").lower() if ans in ['s']: self.testers.write()
def switchFeedback(self): self._getTestersByFeedback() msg = "Switch tester: [<number>/s/q]" self.listTesters() number = User.request(msg) while number.lower() not in ['s', 'save', 'q', 'quit']: if number == '': continue try: number = int(number) self.feedbacks[number].switchFeedback() except (ValueError, IndexError) as e: print(e) exit(1) finally: self.listTesters() number = User.request(msg) if number in ['s', 'save']: self.testers.write() self.listTesters()
def exportDocs(self, version): branchName = "import-v{}".format(version) if not goTo(DOCSDIR): User.pause() return if check_call(shlex.split("make websitedoc")) != 0: print("error while calling 'make websitedoc'") exit(3) Git.chdirToRepositoryTopLevel() if not goTo("website"): User.pause() return Git.checkout(branchName, create=True) Git.add('.') Git.commit("update for offlineimap v{}".format(version)) User.pause( "website: branch '{}' is ready for a merge in master!".format( branchName)) goTo('..') return branchName
def login_user(user:UserSignIn): """Login a registered user.""" user_data=User().get_user_by_email(user.email) if user_data and bcrypt.checkpw( user.password.encode('utf-8'), user_data['password'].encode('utf-8')): token = jwtUtils.generate_jwt( {'id':user_data['id'],'email':user_data['email'],'fullname':user_data['fullname'],'username':user_data['username'] }) user_data.pop('password') return { "status":True, "message":"User successfully Logged in.", "data":{ **user_data, "access_token":token } } else: raise HTTPException( status_code=status.HTTP_400_BAD_REQUEST, detail='Invalid Email or Password' )
def get_all_users(): """Get all users""" users = User().get_all_users() p = [user.pop('password') for user in users] if not users: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, detail='No users found.' ) return { 'status':True, 'message':f'Successfully fetched {len(users)} users.', 'data':users }
def get_user_by_id(id:str): """Get user by id""" if not check_valid_id(id): raise HTTPException( status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, detail='User ID is invalid.' ) user = User().get_user(id) if not user: raise HTTPException( status_code=status.HTTP_404_NOT_FOUND, detail='This user does not exist.' ) user['data'].pop('password') user['data']['tweets'] = Tweet().get_all_user_tweets(id) return { 'status':True, 'message':'User successfully fetched.', 'data':user['data'] }
def login(): """Log user in""" # Forget any user_id session.clear() # User reached route via POST (as by submitting a form via POST) if request.method == "POST": # Ensure username was submitted if not request.form.get("username"): return apology("must provide username", 403) # Ensure password was submitted elif not request.form.get("password"): return apology("must provide password", 403) # Query database for username db_obj = db.execute("SELECT * FROM users WHERE username = :username", username=request.form.get("username")) # Ensure username exists and password is correct if len(db_obj) != 1 or not check_password_hash( db_obj[0]["hash"], request.form.get("password")): return apology("invalid username and/or password", 403) # Remember which user has logged in session["user_id"] = db_obj[0]["id"] # Create user object global user user = User(db_obj) # Redirect user to home page return redirect("/") # User reached route via GET (as by clicking a link or via redirect) else: return render_template("login.html")
def requestVersion(self, currentVersion): User.request("going to make a new release after {}".format(currentVersion))
release = Release() Git.chdirToRepositoryTopLevel() try: release.prepare() currentVersion = release.getVersion() release.requestVersion(currentVersion) release.updateVersion() newVersion = release.getVersion() release.checkVersions(currentVersion, newVersion) release.updateChangelog() release.writeAnnounce() User.pause() release.make() release.updateWebsite(newVersion) release.after() websiteBranch = release.getWebsiteBranch() print(END_MESSAGE.format( announce=ANNOUNCE_FILE, new_version=newVersion, website_branch=websiteBranch) ) except Exception as e: release.restore() raise
print("Will read headers from {}".format(UPCOMING_HEADER)) Git.chdirToRepositoryTopLevel() oVersion = offlineimapInfo.getVersion() ccList = Testers.listTestersInTeam() authors = Git.getAuthorsList(oVersion) for author in authors: email = author.getEmail() if email not in ccList: ccList.append(email) with open(UPCOMING_FILE, 'w') as upcoming, \ open(UPCOMING_HEADER, 'r') as fd_header: header = {} header['messageId'] = Git.buildMessageId() header['date'] = Git.buildDate() header['name'], header['email'] = Git.getLocalUser() header['mailinglist'] = MAILING_LIST header['expectedVersion'] = User.request("Expected new version?") header['ccList'] = ", ".join(ccList) upcoming.write(fd_header.read().format(**header).lstrip()) upcoming.write(Git.getShortlog(oVersion)) upcoming.write("\n\n# Diffstat\n\n") upcoming.write(Git.getDiffstat(oVersion)) upcoming.write("\n\n\n-- \n{}\n".format(Git.getLocalUser()[0])) system("{} {}".format(EDITOR, UPCOMING_FILE)) print("{} written".format(UPCOMING_FILE))
#!/usr/bin/env python3 # -*- coding: utf-8 -*- from os import chdir import os.path import pandas as pd import curses import numpy as np from helpers import is_annotated, Finding, RightSideMenu, MasterTable, fish, ProgressBar, User, Confidence current_annotator = User() class SimpleAnnotaor(object): def __init__(self): self.foo = "bar" def check_untypical_length(self, text): if len(text) < 250 or len(text) > 2000: return True else: return False simple_annotator = SimpleAnnotaor() def scroll_reports(key, row, n_row): if key == ord('n') or key == curses.KEY_RIGHT: if row < (n_row - 1): row += 1