Ejemplo n.º 1
0
 def post(self, token):
     form = PasswordResetForm()
     if not form.validate():
         return render_template(self.template, form=form)
     user = UserModel.objects(email=form.email.data).first()
     if user is None:
         return redirect('index.index')
     if user.reset_password(token, form.password.data):
         flash('Your password has been updated.')
         return redirect(url_for('index.index'))
     else:
         return redirect(url_for('index.index'))
Ejemplo n.º 2
0
 def post(self):
     form = PasswordResetRequestForm()
     if not form.validate():
         return render_template(self.template, form=form)
     user = UserModel.objects(email=form.email.data).first()
     if user:
         token = user.generate_reset_token()
         send_email.delay(
             user.email,
             'Reset Your Password',
             'auth/email/reset_password',
             user=user, token=token,
             next=request.args.get('next')
         )
     flash('An email with instructions to reset your password has been '
           'sent to you.')
     return redirect(url_for('index.index'))
Ejemplo n.º 3
0
    def post(self):
        form = ContestCreateForm()
        if form.add.data:
            try:
                form.problems.append_entry()
            except:
                flash('Problem field cannot be longer than 26.')
            finally:
                for index, entrie in enumerate(form.problems.entries):
                    entrie.index.data = chr(index + 65)
            return render_template(self.template, form=form)

        for index, entrie in enumerate(form.problems.entries):
            if entrie.delete.data:
                form.problems.entries.pop(index)
                for index, entrie in enumerate(form.problems.entries):
                    entrie.index.data = chr(index + 65)
                return render_template(self.template, form=form)

        if not form.validate():
            for index, entrie in enumerate(form.problems.entries):
                entrie.index.data = chr(index + 65)
            return render_template(self.template, form=form)

        contest = form.generate_contest()

        for index, entrie in enumerate(form.problems.entries):
            problem = entrie.generate_problem(chr(index + 65))
            contest.problems.append(problem)

        contest.manager = UserModel.objects(
            username=current_user.username
        ).first()
        contest.save()
        return redirect(
            url_for(
                'contest.detail',
                contest_id=contest.contest_id
            )
        )
Ejemplo n.º 4
0
    def post(self, origin_oj, problem_id):
        form = SubmitForm(origin_oj, problem_id)
        account = current_user.get_account(form.origin_oj.data)
        if not form.validate():
            return render_template(
                self.template,
                form=form,
                origin_oj=form.origin_oj.data,
                problem_id=form.problem_id.data
            )
        if account is None or account.status != 'Authentication Success':
            flash('Please bind the correct account.')
            return redirect(
                url_for(
                    'problem.detail',
                    origin_oj=form.origin_oj.data,
                    problem_id=form.problem_id.data,
                )
            )

        solution = form.generate_solution()
        solution.user = UserModel.objects(
            username=current_user.username
        ).first()
        solution.save()
        code_submit.delay(
            form.origin_oj.data,
            solution.solution_id,
            form.problem_id.data,
            form.language.data,
            form.code.data,
            account.username,
            account.nickname,
            account.password
        )

        return redirect(url_for('solution.list'))
Ejemplo n.º 5
0
 def validate_email(self, field):
     if UserModel.objects(email=field.data):
         raise ValidationError('Email has already been registered')
Ejemplo n.º 6
0
 def validate_username(self, field):
     if UserModel.objects(username=field.data):
         raise ValidationError('Username already in use')
Ejemplo n.º 7
0
 def validate_email(self, field):
     if not UserModel.objects(email=field.data):
         raise ValidationError('Unknown email address.')
Ejemplo n.º 8
0
 def validate_email(self, field):
     if not UserModel.objects(email=self.email.data):
         raise ValidationError('Email is invalid')