Exemplo n.º 1
0
def home():
    print "config.AUTHENTICATE {}".format(config.AUTHENTICATE)
    if config.AUTHENTICATE:
        return render_template('index.html',
                               login_form=LoginForm(),
                               create_form=CreateAccountForm())
    else:
        email = 'default'
        password = '******'
        access_key_id = config.AWS_ID
        secret_access_key = config.AWS_KEY
        aws_bucket_name = config.AWS_BUCKET_NAME
        next_backend_global_host = config.NEXT_BACKEND_GLOBAL_HOST
        if not User.objects(email=email):
            user = User(email=email,
                        access_key_id=access_key_id,
                        secret_access_key=secret_access_key,
                        aws_bucket_name=aws_bucket_name,
                        next_backend_global_host=next_backend_global_host)
            user.set_password(password)
            user.save()
        else:
            user = User.objects(email=email).first()
        login_user(user, remember=True)
        return redirect(url_for('dashboard._dashboard'))
    def test_switch_user_message_handler(self):
        user_id = 1
        handler_code1 = "handler1"
        handler_code2 = "handler2"
        self.server.set_message_handler(self.message_handler,
                                        handler_code1,
                                        default=True)

        # handler is not setted
        self.assertRaises(MessageHandlerNotSettedException,
                          self.server.switch_user_message_handler, user_id,
                          handler_code2)

        # set special handler for user
        self.server.set_message_handler(self.message_handler, handler_code2)
        self.server.switch_user_message_handler(user_id, handler_code2)
        self.assertEqual(
            User.objects(user_id=str(user_id)).first().next_handler,
            handler_code2)

        # set default handler for user
        self.server.switch_user_message_handler(user_id, None)
        self.assertEqual(
            User.objects(user_id=str(user_id)).first().next_handler,
            handler_code1)
Exemplo n.º 3
0
def login():
    login_form = LoginForm(request.form)
    if login_form.validate_on_submit():
        user = User.objects(email=login_form.email.data).first()
        if user and user.check_password(login_form.password.data):
            login_user(user)
            return redirect(request.args.get("next") or url_for('dashboard._dashboard'))
        else:
            flash("Login failed.", "login_error")
            # login is not valid
            return redirect('#create')
    return render_template('index.html', login_form=login_form, create_form=CreateAccountForm())
Exemplo n.º 4
0
def login():
    login_form = LoginForm(request.form)
    if login_form.validate_on_submit():
        user = User.objects(email=login_form.email.data).first()
        if user and user.check_password(login_form.password.data):
            login_user(user)
            return redirect(request.args.get("next") or url_for('dashboard._dashboard'))
        else:
            flash("Login failed.", "login_error")
            # login is not valid
            return redirect('#create')
    return render_template('index.html',
                           login_form=login_form,
                           create_form=CreateAccountForm())
Exemplo n.º 5
0
def create():
    create_form = CreateAccountForm(request.form)
    if create_form.validate_on_submit():
        print "form data",create_form.new_email.data
        new_email = create_form.new_email.data
        new_password = create_form.new_password.data
        confirm_password = create_form.confirm_password.data
        print User.objects()
        if User.objects(email=new_email).count() == 0:
            if new_password == confirm_password:
                # Set the hashed password on the user.
                user = User(email=new_email)
                user.set_password(new_password)
                user.save()
                login_user(user, remember=True)
                return redirect(url_for('dashboard._dashboard'))
            else:
                flash("Passwords don't match!", "create_error")
                return redirect('#create')    
        else:
            flash("Username exists!", "create_error")
            return redirect('#create')
    # login form is not valid
    return render_template('index.html', login_form=LoginForm(), create_form=create_form)
    def test_handle_postback(self, mock_obj):
        handler_code = "handler"
        sender_id = 1
        postback = {"payload": handler_code}

        # message handler not setted up
        self.assertRaises(PostbackHandlerUndefinedException,
                          self.server.handle_postback, postback, sender_id)

        # handle message
        self.server.set_postback_handler(self.message_handler, handler_code)
        self.server.handle_postback(postback, sender_id)
        self.assertEqual(
            User.objects(user_id=str(sender_id)).first().next_handler,
            "special_handler")
Exemplo n.º 7
0
def create():
    create_form = CreateAccountForm(request.form)
    if create_form.validate_on_submit():
        print "form data",create_form.new_email.data
        new_email = create_form.new_email.data
        new_password = create_form.new_password.data
        confirm_password = create_form.confirm_password.data
        print User.objects()
        if User.objects(email=new_email).count() == 0:
            if new_password == confirm_password:
                # Set the hashed password on the user.
                user = User(email=new_email)
                user.set_password(new_password)
                user.save()
                login_user(user, remember=True)
                return redirect(url_for('dashboard._dashboard'))
            else:
                flash("Passwords don't match!", "create_error")
                return redirect('#create')    
        else:
            flash("Username exists!", "create_error")
            return redirect('#create')
    # login form is not valid
    return render_template('index.html', login_form=LoginForm(), create_form=create_form)
    def test_handle_message(self, mock_obj):
        message = {'text': "test"}
        sender_id = 1
        handler_code = "handler"

        # message handler not setted up
        self.assertRaises(MessageHandlerNotSettedException,
                          self.server.handle_message, message, sender_id)

        # handle message
        self.server.set_message_handler(self.message_handler,
                                        handler_code,
                                        default=True)
        self.server.handle_message(message, sender_id)
        self.assertEqual(
            User.objects(user_id=str(sender_id)).first().next_handler,
            "special_handler")
Exemplo n.º 9
0
def load_user(userid):
    users = User.objects(email=userid)
    if len(users) >0:
        return users[0]
    return None
Exemplo n.º 10
0
def load_user(userid):
    users = User.objects(email=userid)
    if len(users) > 0:
        return users[0]
    return None