コード例 #1
0
def register():
    data = json.loads(request.data)
    email = data['email']
    username = data['name']
    password = data['password']

    try:
        app.logger.debug("Registration attempt ('%s', '%s')" % (username, email))

        if (db.email_exists(email)):
            app.logger.debug("Registration for '%s' failed - email already taken" % email)
            return jsonify({"success":False, "error_message":"email already registered"}), 409

        if (db.username_exists(username)):
            app.logger.debug("Registration for '%s' failed - username already taken" % username)
            return jsonify({"success":False, "error_message":"username already taken"}), 409

        if (len(password) < 8):
            app.logger.debug("Registration for '%s' failed - password too short" % username)
            return jsonify({"success":False, "error_message":"password too short"}), 422

        if (len(password) > 64):
            app.logger.debug("Registration for '%s' failed - password too long" % username)
            return jsonify({"success":False, "error_message":"password too long"}), 422

        db.add_new_user(email, username, password)
        app.logger.info("Registered new user ('%s', '%s')" % (username, email))

        return jsonify({"success":True}), 201

    except Exception as e:
        app.logger.error("Error while processing registration ('%s', '%s')\n%s" % (username, email, e))
        return jsonify({"success":False, "error_message":"internal server error"}), 500
コード例 #2
0
ファイル: main.py プロジェクト: Bobberclobber/agora
def register_user(user_name, password, e_mail, country, city, avatar_image):
    if db.email_exists(e_mail):
        return jsonify({"response": ["E-Mail Already Registered"]})
    elif db.user_name_exists(user_name):
        return jsonify({"response": ["User Name Taken"]})
    else:
        db.add_new_user(user_name, password, e_mail, country, city, avatar_image)
        return jsonify({"response": ["Success"]})
コード例 #3
0
def register_user(user_name, password, e_mail, country, city, avatar_image):
    if db.email_exists(e_mail):
        return jsonify({"response": ["E-Mail Already Registered"]})
    elif db.user_name_exists(user_name):
        return jsonify({"response": ["User Name Taken"]})
    else:
        db.add_new_user(user_name, password, e_mail, country, city, avatar_image)
        return jsonify({"response": ["Success"]})
コード例 #4
0
ファイル: login.py プロジェクト: morlov/rankit
    def post(self):
        
        user_name = self.request.get('user_name')
        password = self.request.get('password')
        verify = self.request.get('verify')
        email = self.request.get('email')

        error_login = valid_signup(self, email, password, verify, user_name)
        
        if error_login:
            self.render('signup.html', error_login=error_login, email=email, password=password, verify=verify, user_name=user_name)
        else:
            database.add_new_user(user_name=user_name, password=password, email=email)
            self.set_current_user(user_name)
            self.redirect('/')
コード例 #5
0
def register(email, password, user_type, first_name, second_name, middle_name,
             organization_name):
    if validate_email_exist(email) == "email already exists":
        return "user already exists"
    if validate_input(email, password) == "invalid":
        return "invalid"
    if validate_first_name(first_name) == INVALID:
        return INVALID
    if validate_second_name(second_name) == INVALID:
        return INVALID
    # if validate_organization_name(organization_name) == INVALID:
    #     return INVALID
    if verify_hashed_password(password) == INVALID:
        return INVALID

    new_user_type = user_type_validation(user_type)
    if new_user_type == INVALID_USER_TYPE_MESSAGE:
        return INVALID_USER_TYPE_MESSAGE
    hashed_password = hash_password(password)

    new_user_id = database.add_new_user(email, hashed_password, new_user_type,
                                        created_time_utc, modified_time_utc,
                                        first_name, second_name, middle_name,
                                        organization_name)
    if len(new_user_id) > 0:
        return "registered"
    return None
コード例 #6
0
def register(userId):

    register = add_new_user(ref, userId)
    response = {"success": False}

    if register:
        response['success'] = True
        response = json.dumps(response)
        return response
    else:
        response['success'] = False
        response = json.dumps(response)
        return response
コード例 #7
0
ファイル: login.py プロジェクト: morlov/rankit
    def post(self):

        user_name = self.request.get('user_name')
        password = self.request.get('password')
        verify = self.request.get('verify')
        email = self.request.get('email')

        error_login = valid_signup(self, email, password, verify, user_name)

        if error_login:
            self.render('signup.html',
                        error_login=error_login,
                        email=email,
                        password=password,
                        verify=verify,
                        user_name=user_name)
        else:
            database.add_new_user(user_name=user_name,
                                  password=password,
                                  email=email)
            self.set_current_user(user_name)
            self.redirect('/')
コード例 #8
0
def create_profile():
    # TODO : show something if you need to log out first!
    if request.method == 'GET':
        return render_template('create_profile.html')
    username = request.form['username']
    encrypted_password = sha256_crypt.encrypt(request.form['password'])
    added_successfully = db.add_new_user(username, encrypted_password)
    if not added_successfully:
        flash("Username: {} is already taken".format(username))
        return render_template('create_profile.html')
    SESSION["logged in"] = True
    SESSION["user"] = username
    flash("Welcome {}!".format(username))
    return redirect(url_for('view_profile'))
コード例 #9
0
def create_user_by_admin(email, password, user_type, first_name, second_name,
                         middle_name, organization_name, logged_in_admin_id):
    if validate_email_address(email) == INVALID:
        return INVALID
    if check_email_address_exist(email) == EMAIL_EXIST:
        return EMAIL_EXIST
    if validate_password(password) == INVALID:
        return INVALID
    if verify_hashed_password(password) == INVALID:
        return INVALID
    if validate_user_type(user_type) == INVALID:
        return INVALID
    if validate_user_type(user_type) == INVALID_USER_TYPE_MESSAGE:
        return INVALID_USER_TYPE_MESSAGE
    if validate_first_name(first_name) == INVALID:
        return INVALID
    if validate_second_name(second_name) == INVALID:
        return INVALID
    # if validate_organization_name(organization_name) == INVALID:
    #     return INVALID
    if user_badge_mapping.validate_user_id_for_admin(
            logged_in_admin_id) == "User ID is not valid":
        return "logged in admin user ID is not valid"

    if user_badge_mapping.validate_user_id_for_admin(
            logged_in_admin_id) == "User ID not Present in User collection DB":
        return "logged in admin user ID not Present in User collection DB"

    if user_badge_mapping.validate_user_id_for_admin(
            logged_in_admin_id) == "Requesting user is not an admin":
        return "Requesting user is not an admin to create user"

    hashed_password = hash_password(password)
    new_user_id = database.add_new_user(email, hashed_password, user_type,
                                        created_time_utc, modified_time_utc,
                                        first_name, second_name, middle_name,
                                        organization_name)
    if len(new_user_id) > 0:
        return "registered"
    return None
コード例 #10
0
def login_or_register():
    """
    combines all  login and registration methods:
    1) google (third-party)
    2) (optional) email - password combination: available when  ENABLE_EMAIL_AND_PASSWORD_LOGIN_AND_REGISTRATION
    option is set to True
    """

    simple_login_form = LoginForm()
    simple_register_form = RegisterForm()
    state = lib.get_random_string()
    login_session["state"] = state
    login_error_message = ""
    registration_error_message = ""
    if options.ENABLE_EMAIL_AND_PASSWORD_LOGIN_AND_REGISTRATION:
        if request.method == 'POST':
            if request.form[
                    "action"] == "simple_login" and simple_login_form.validate_on_submit(
                    ):
                lib.debug_print("processing login")

                login_error_message, user = get_errors_in_login_data(
                    email=simple_login_form.email.data,
                    password=simple_login_form.password.data)
                if login_error_message == "":
                    database.set_user_authenticated_status(user, True)
                    flask_login.login_user(user, remember=True)
                    authorize_user(user.id)

                    # no need to flash as user will be shown "logged in as" message any way
                    return redirect(url_for("index"))

            elif request.form[
                    "action"] == "simple_register" and simple_register_form.validate_on_submit(
                    ):
                lib.debug_print("processing register")
                registration_error_message = \
                    get_errors_in_registration_data(email=simple_register_form.email.data,
                                                    password=simple_register_form.password.data,
                                                    confirmed_password=simple_register_form.confirm_password.data)

                if registration_error_message == "":
                    database.add_new_user(
                        name=simple_register_form.name.data,
                        email=simple_register_form.email.data,
                        phone_number=simple_register_form.phone.data,
                        password=simple_register_form.password.data)

                    flash('Successfully created new user ' +
                          simple_register_form.email.data + ". Please log in.")

    return render_template(
        "login_or_register.html",
        simple_login_form=simple_login_form,
        simple_register_form=simple_register_form,
        google_session_state=login_session["state"],
        simple_login_error_message=login_error_message,
        simple_register_error_message=registration_error_message,
        page_info=get_page_info(),
        ENABLE_EMAIL_AND_PASSWORD_LOGIN_AND_REGISTRATION=options.
        ENABLE_EMAIL_AND_PASSWORD_LOGIN_AND_REGISTRATION)