Python models.User 模块,email() 实例源码

我们从Python开源项目中,提取了以下14个代码示例,用于说明如何使用models.User.email()

项目:rp2017-codegolf    作者:ReflectionsProjections    | 项目源码 | 文件源码
def post(self):
        '''Endpoint for getting auth token for existing user'''
        parser = reqparse.RequestParser()
        parser.add_argument('email', required=True)
        parser.add_argument('password', required=True)
        args = parser.parse_args()
        hash_obj = hashlib.sha256()
        hash_obj.update(args.password.encode('utf-8'))
        password_hash = hash_obj.hexdigest()
        user = db.session.query(User).filter((User.email==args.email) & (User.password_hash==password_hash)).first()
        if user is None:
            return redirect('/?message=%s' % 'Could not find account.')

        # allocate and maintain session token
        token = os.urandom(256)
        tokens[token] = args.email
        session['token'] = token
        session['username'] = user.username
        return redirect('/')
项目:infilcheck    作者:jonnykry    | 项目源码 | 文件源码
def request_loader(request):
    email = request.form.get('email')

    if email is None:
        return

    password = request.form['pw']

    loaded_user = None

    user = db.session.query(User).filter(User.email == email).first()

    if user is None:
        return

    user.is_authenticated = user.check_password(password)
    loaded_user = user

    return loaded_user
项目:infilcheck    作者:jonnykry    | 项目源码 | 文件源码
def login():

    if flask.request.method == 'GET':
        return render_template('login.html')

    email = request.form['email']
    password = request.form['pass']

    for user in db.session.query(User).filter(User.email == email):
        print('Login Result: ' + user.email, file=sys.stderr)

        if user.check_password(password):
            flask_login.login_user(user)
            return redirect('dashboard')

    return redirect('login_failed')
项目:infilcheck    作者:jonnykry    | 项目源码 | 文件源码
def register():
    if request.method == 'POST':
        email = request.form['email']
        password = request.form['password']
        phone = flask.request.form['phone']

        if email is not None and password is not None and phone is not None:
            user = User(email, password, phone)
            db.session.add(user)
            db.session.commit()

            flags = Flags(user.id, False, False, False)
            pi = Pi(user.id, datetime.utcnow())

            db.session.add(flags)
            db.session.add(pi)
            db.session.commit()

            flask_login.login_user(user)

            return redirect('dashboard')
        else:
            print('Error creating user: ' + str(email), file=sys.stderr)

    return render_template('register.html')
项目:rp2017-codegolf    作者:ReflectionsProjections    | 项目源码 | 文件源码
def post(self):
        '''Endpoint for registering and getting auth token for new user'''
        parser = reqparse.RequestParser()
        parser.add_argument('username', required=True)
        parser.add_argument('email', required=True)
        parser.add_argument('password', required=True)
        args = parser.parse_args()

        # check username and email uniqueness
        duplicate = db.session.query(User).filter((User.username==args.username) | (User.email==args.email)).first()
        if duplicate is not None:
            return redirect('/?message=%s' % 'Account already exists for this email.')

        hash_obj = hashlib.sha256()
        hash_obj.update(args.password.encode('utf-8'))
        user_obj = User(
            username=args.username,
            email=args.email,
            password_hash=hash_obj.hexdigest()
        )
        db.session.add(user_obj)
        db.session.commit()

        # allocate and maintain session token
        token = os.urandom(256)
        tokens[token] = args.email
        session['token'] = token
        session['username'] = args.username
        return redirect('/')
项目:Flask-Social-Networking    作者:sinscary    | 项目源码 | 文件源码
def email_exists(form,field):
    if User.select().where(User.email == field.data).exists():
        raise ValidationError('User with this email already exists.')
项目:dark-chess    作者:AHAPX    | 项目源码 | 文件源码
def is_valid(self):
        if len(self.form['username']) < 4:
            return self.error('username must be at least 4 characters')
        if self.form['username'] == 'anonymous':
            return self.error('username cannot be anonymous')
        if len(self.form['password']) < 8:
            return self.error('password must be at least 8 characters')
        if User.select().where(User.username == self.form['username']).count():
            return self.error('username is already in use')
        if self.form['email']:
            if not validate_email(self.form['email']):
                return self.error('email is not valid')
            if User.select().where(User.email == self.form['email']).count():
                return self.error('email is already in use')
        return super(RegistrationValidator, self).is_valid()
项目:dark-chess    作者:AHAPX    | 项目源码 | 文件源码
def is_valid(self):
        if not validate_email(self.form['email']):
            return self.error('email is not valid')
        return super(ResetValidator, self).is_valid()
项目:infilcheck    作者:jonnykry    | 项目源码 | 文件源码
def user_loader(email):
    users = db.session.query(User).filter(User.email == email)

    if users is None:
        return

    temp_user = None

    for user in users:
        temp_user = user

    if temp_user is None:
        return

    return temp_user
项目:infilcheck    作者:jonnykry    | 项目源码 | 文件源码
def settings():
    if request.method == 'POST':
        email = request.form['email']
        curpassword = request.form['curpassword']
        password = request.form['password']
        phone = flask.request.form['phone']
        pi_id = flask.request.form['piid']

        room_name = flask.request.form['room_name']
        capture_framerate = flask.request.form['capture_framerate']
        output_framerate = flask.request.form['output_framerate']
        threshold_frame_count = flask.request.form['threshold_frame_count']

        current_user = User.query.filter_by(id=flask_login.current_user.id).first()

        if pi_id == 'true':
           current_user.pi_id = str(uuid.uuid4())

        if current_user.check_password(curpassword) and password is not '':
            current_user.passhash = generate_password_hash(password)

        current_user.email = email
        current_user.phone = phone

        pi_data = Pi.query.filter_by(id=flask_login.current_user.id).first()
        pi_data.room_name = room_name
        pi_data.capture_framerate = capture_framerate
        pi_data.output_framerate =output_framerate
        pi_data.threshold_frame_count = threshold_frame_count

        flag=Flags.query.filter_by(id=flask_login.current_user.id).first()
        flag.request_update_settings = True

        db.session.commit()

        return redirect('settings')

    return render_template('settings.html', user_data = flask_login.current_user, pi_data = Pi.query.filter_by(id=flask_login.current_user.id).first())
项目:TodoListMaker    作者:prakharchoudhary    | 项目源码 | 文件源码
def email_exists(form, field):
    if User.select().where(User.email == field.data).exists():
        raise ValidationError('User with that email already exists.')
项目:flask_yzd    作者:qqxx6661    | 项目源码 | 文件源码
def sign_up():
    form = SignUpForm()
    user = User()
    if form.validate_on_submit():
        user_name = request.form.get('user_name')
        user_email = request.form.get('user_email')
        password = request.form.get('password')
        password = generate_password_hash(password)
        register_check = User.query.filter(db.or_(
            User.nickname == user_name, User.email == user_email)).first()
        if register_check:
            flash("????????")
            return redirect('/sign-up')

        if len(user_name) and len(user_email):
            user.nickname = user_name
            user.email = user_email
            user.role = ROLE_USER
            user.password = password
            try:
                db.session.add(user)
                db.session.commit()
            except:
                flash("???????????")
                return redirect('/sign-up')

            flash("????")
            return redirect('/login')

    return render_template("sign_up.html", form=form)
项目:flask-social    作者:sethbergman    | 项目源码 | 文件源码
def email_exists(form, field):
    if User.select().where(User.email == field.data).exists():
        raise ValidationError('User with that email already exists.')
项目:rp2017-codegolf    作者:ReflectionsProjections    | 项目源码 | 文件源码
def post(self, task_id):
        ''' Endpoint for submitting code '''
        parser = reqparse.RequestParser()
        parser.add_argument('language', required=True)
        parser.add_argument('code', required=True)
        args = parser.parse_args()
        task = manager.get_task(task_id)
        if task_id is None or task is None:  # no task exists with the stated id
            return redirect('/?message=%s' % 'task does not exist.')
        test_cases = task.get('test_cases', None)
        # get user id
        if 'token' not in session:
            try:
                session.pop('username')
            except KeyError: pass
            return redirect('/?message=%s' % 'no auth token supplied.')
        if session['token'] not in tokens:
            try:
                session.pop('username')
            except KeyError: pass
            session.pop('token')
            return redirect('/?message=%s' % 'invalid token supplied.')
        user = db.session.query(User).filter(User.email==tokens[session['token']]).first()

        # verify response using same input
        result = docker_verify(args.code, args.language, test_cases)
        if result is None:
            return redirect('/?task=%d&message=%s' % (task_id, 'language is not supported'))
        if all(result):
            if(len(args.code) < best_answer[task_id][args.language]):
                best_answer[task_id][args.language] = len(args.code)
            max_points = int(task.get('points', None))
            points = max_points * best_answer[task_id][args.language]/len(args.code)

            # look for better answer from same user
            prev_answer = db.session.query(Answer).filter((Answer.user_id==user.id) & (Answer.task_id==task_id) & (Answer.points>points)).first()
            if prev_answer is None:
                answer = Answer(
                    user_id=user.id,
                    task_id=task_id,
                    length=len(args.code),
                    points=points,
                    language=args.language
                )
                db.session.add(answer)
                user.points = sum([answer.points for answer in user.answers])
                db.session.commit()
            return redirect('/?task=%d&message=%s' % (task_id, 'answer judged correct.'))
        return redirect('/?task=%d&message=%s' % (task_id, 'answer judged incorrect.'))