def post(self): parser = reqparse.RequestParser() parser.add_argument("wallet", type=wallet_is_valid, required=True) parser.add_argument("password", type=str, required=True) parser.add_argument("confirmation", type=str, required=True) parser.add_argument("email", type=str, default=None, required=False) args = parser.parse_args() player = Player() player.wallet = args.get('wallet') player.set_password(args.get('password')) player.email = args.get('email') player.active = True player.save() login_user(player, remember=True) return player
def wallet_is_valid(value, name, *args): wallet_regex = '^[13][1-9A-HJ-NP-Za-km-z]{26,33}' if not re.match(wallet_regex, value): raise FieldValueError(name, "Bitcoin wallet format is incorrect") if Player.select().where(Player.wallet == value).count() > 0: raise FieldValueError(name, "Bitcoin wallet already is used by another user") return value
def post(self): form = LoginForm() if form.validate_on_submit(): try: player = Player.login(form) except: return render_template("login.html", form=form, invalid=True) else: login_user(player, remember=True) return redirect(request.args.get("next") or url_for("index")) return render_template("login.html", form=form)
def post(self): form = SignupForm() if form.validate_on_submit(): player = Player() player.wallet = form.wallet.data player.email = form.email.data player.active = True player.set_password(form.password.data) player.save() login_user(player, remember=True) flash("User signup successfully...") return redirect(request.args.get("next") or url_for("index")) return render_template("signup.html", form=form)
def post(self): parser = reqparse.RequestParser() parser.add_argument("wallet", type=str, required=True) parser.add_argument("password", type=str, required=True) args = parser.parse_args() try: player = Player.login(args.get('wallet'), args.get('password')) except: return abort(404, message="Invalid provided credentials") login_user(player, remember=True) return player
def load_user(player_id): return Player.select().where(Player.id == player_id).get()