Exemplo n.º 1
0
def index():

    form = UserCreateForm()

    if form.validate_on_submit():

        if not form.validate_on_submit():
            return form.errors, 422

        user = User(form.email.data, form.password.data)
        db.session.add(user)
        db.session.commit()

    return render_template('index.html', form=form)
Exemplo n.º 2
0
def signup():
    form = UserCreateForm()
    if request.method == 'POST' and form.validate_on_submit():
        request_data = {
            'group': form.group.data,
            'name': form.name.data,
            'email': form.email.data,
            'password': generate_password_hash(form.password1.data)
        }
        collection = db['users']
        user_data = collection.find_one(
            filter={'email': request_data['email']})
        if user_data:
            flash('이미 존재하는 사용자입니다.')
        else:
            user_data = collection.find_one(
                filter={'group': request_data['group']})
            request_data['admin'] = False
            if user_data is None:
                request_data['admin'] = True
            user_data = collection.find_one(sort=[('create_time', -1)])
            if user_data:
                user_id = user_data['user_id'] + 1
            else:
                user_id = 1
            request_data['create_time'] = str(datetime.now())
            request_data['user_id'] = user_id
            collection.insert(request_data)
            return redirect(url_for('main.index'))
    return render_template('/signup.html', form=form)
Exemplo n.º 3
0
    def post(self):
        form = UserCreateForm()
        if not form.validate_on_submit():
            return form.errors, 422

        user = User(form.email.data, form.password.data)
        db.session.add(user)
        db.session.commit()
        return UserSerializer(user).data
Exemplo n.º 4
0
def login():
    form = LoginForm()
    formCreate=UserCreateForm()
    providers = ["Facebook", "Google", "Twitter"]
    erromsg="" 

    if form.validate_on_submit() or form.provider.data=="facebook":

        provider = form.provider.data
        session['remember_me'] = form.remember_me.data
        session['provider'] = provider
        if provider == "google":
            callback=url_for('account.google_authorized', _external=True)
            return google.authorize(callback=callback)
        elif provider == "twitter":
            callback=url_for('account.twitter_authorized',
                next=request.args.get('next') or request.referrer or None,
                _external=True)
            return twitter.authorize(callback=callback)
        elif provider == "facebook":
            callback=url_for('account.facebook_authorized',
                next=request.args.get('next') or request.referrer or None,
                _external=True)
            return facebook.authorize(callback=callback)
        else:
            if form.password is not None:
                return after_login( email=form.email.data, 
                               password=form.password.data)
        
    if formCreate.validate_on_submit():
        return after_login(fullname=formCreate.fullname.data, nickname=formCreate.nickname.data, 
                           language="pt", country="br", image="image",email=formCreate.email.data, 
                           password=formCreate.password.data)

    return render_template('account/login.html', 
        form = form,formCreate=formCreate,
        providers = providers)