def run(self): user = User.from_username(self.args.user) if user is None: print(f"No user with username {self.args.user} found!") exit(1) contest = Contest.from_name(self.args.contest) contest.remove_user(user)
def run(self): print( tabulate(User.users(), headers=[ "Id", "First name", "Last name", "Username", "Email", "Password", "Privilege" ]))
def register(): if not config.get("allow_registration", False): return abort(403) if request.method == "GET": return render_template("register.html") # TODO: validate all data properly username = request.form["username"] assert len(username) > 0 first_name = request.form["first_name"] assert len(first_name) > 0 last_name = request.form["last_name"] assert len(last_name) > 0 email = request.form["email"] assert re.match("[^@]+@[^@]+\.[^@]+", email) password = request.form["password"] password2 = request.form["password2"] assert len(password) > 4 and password == password2 user = User.insert( username=username, first_name=first_name, last_name=last_name, email=email, password=password, ) session.set_current_user(user) return redirect(url_for("root.home"))
def user_view(username): user = User.from_username(username) if user.privilege == UserPrivilege.STANDARD and user != session.get_current_user( ): return abort(403) contests = Contest.of_user(user) return render_template("user.html", user=user, contests=contests)
def run(self): user = User.from_username(self.args.username) if user is None: print(f"No user with username '{self.args.username}' exists!", file=sys.stderr) exit(1) if not self.args.yes: confirm = input(f"Really delete user {self.args.username}? (y/n) ") if confirm != "y": exit(0) user.delete()
def run(self): user = User.from_username(self.args.username) if user is None: print(f"No user with username '{self.args.username}' exists!", file=sys.stderr) exit(1) if not self.args.yes: confirm = input( f"Setting privilege of user {self.args.username} to {self.args.privilege}. Confirm? (y/n) " ) if confirm != "y": exit(0) user.set_privilege(UserPrivilege(self.args.privilege))
def run(self): print(f"Creating user with username: {self.args.username}") if User.from_username(self.args.username) is not None: print( f"A user with username '{self.args.username}' already exists!", file=sys.stderr) exit(1) if self.args.first_name is None: self.args.first_name = input("First name: ") else: print(f"First name: {self.args.first_name}") if self.args.last_name is None: self.args.last_name = input("Last name: ") else: print(f"Last name: {self.args.last_name}") if self.args.email is None: self.args.email = input("Email: ") else: print(f"Email: {self.args.email}") if self.args.password is None: self.args.password = input("Password (min 8 char): ") else: print(f"Password: {self.args.password}") if not self.args.yes: confirm = input("Is the data inserted correct? (y/n)") if confirm != "y": exit(0) if User.insert( username=self.args.username, first_name=self.args.first_name, last_name=self.args.last_name, email=self.args.email, password=self.args.password, ) is None: print("There was an error inserting the user into the system") else: print( f"The user {self.args.username} was correctly inserted in the system" )
def auth_api(): args = Args() contest = Contest.contest(args.contest) if contest is None: raise ApiError(400, f"Invalid contest {args.contest}") if args.username is None: set_current_user(contest, None) else: user = User.from_username(contest, args.username) if user is None or not user.check_password(args.password): raise ApiError(401, "wrong username or password") set_current_user(args.contest, user) return jsonify(status="OK")
def login(): reg_ok = config.get("allow_registration", False) redirect_url = request.args.get("redirect", None) if request.method == "GET": return render_template("login.html", registrarion_allowed=reg_ok, redirect=redirect_url) username = request.form["username"] password = request.form["password"] user = User.from_username(username) if user.auth(password): session.set_current_user(user) if redirect_url is None: redirect_url = url_for("user.user_view", username=username) return redirect(redirect_url) else: return render_template("login.html", redirect=redirect_url, message="Wrong username or password", registrarion_allowed=reg_ok)
def users(self): return User.from_contest(self)
def user(self): return User.from_id(self.user_id)
def get_current_user(contest): username = session.get(contest, None) if username is None: return None return User.from_username(Contest.contest(contest), username)