Esempio n. 1
0
def register(artifact_id, artifact_hash):
    artifact = Artifact.query.get(artifact_id)
    form = RegisterForm(request.form)
    print(request.method)
    if form.is_submitted():
        print("submitted")
        print(form.email.data)
    if form.validate_on_submit():
        print("valid")
    else:
        print(form.errors)
    if artifact_id is None or artifact.access_hash != artifact_hash:
        flash("invalid artifact id and access hash combination")
        return redirect(url_for('index'))
    if request.method == 'POST' and form.validate_on_submit():
        user = User.get_or_create_user(form.email.data, form.name.data)
        predecessor = Handover.query.join(Artifact).filter(
            Artifact.id == Handover.artifact_id).filter(
                Artifact.id == artifact.id).order_by(
                    Handover.id.desc()).limit(1).one_or_none()
        if predecessor != None:
            predecessor_id = predecessor.id
        else:
            predecessor_id = None
        if form.text.data != "":
            media = Media(type=MediaType.text)
            db.session.add(media)
            db.session.commit()
            text = Text(media_id=media.id, text=form.text.data)
            db.session.add(text)
            db.session.commit()
        handover = Handover(artifact_id=artifact_id,
                            predecessor_id=predecessor_id,
                            lat=form.lat.data,
                            lon=form.lon.data,
                            user_id=user.id)
        handover.media_id = media.id
        db.session.add(handover)
        db.session.commit()
        return redirect(url_for('handover', handover_id=handover.id))
    handover_count = Handover.query.join(Artifact).filter(
        Artifact.id == Handover.artifact_id).count()
    return render_template('register.html',
                           title="Register Handover",
                           form=form,
                           artifact_id=artifact_id,
                           handover_count=handover_count,
                           access_hash=artifact_hash)
Esempio n. 2
0
def register():
    """
    用户注册
    :return:
    """
    if db_utils.get_option('open_user', {}).get('value') != '1':
        abort(403)
    user_form = RegisterForm()
    if user_form.is_submitted():
        if not user_form.validate():
            return jsonify(
                models.Response.fail(code_msg.PARAM_ERROR.get_msg(),
                                     str(user_form.errors)))
        utils.verify_code(user_form.verify_code.data)
        user = mongo.db.users.find_one({'email': user_form.email.data})
        if user:
            return jsonify(code_msg.EMAIL_EXIST)
        user_dict = {
            'is_active':
            False,
            'coin':
            0,
            'email':
            user_form.email.data,
            'username':
            user_form.username.data,
            'vip':
            0,
            'reply_count':
            0,
            'avatar':
            url_for('static',
                    filename='images/avatar/' + str(randint(0, 12)) + '.jpg'),
            'password':
            generate_password_hash(user_form.password.data),
            'create_time':
            datetime.utcnow(),
        }
        mongo.db.users.insert_one(user_dict)
        send_active_email(user['username'], user['_id'], user['email'])
        return jsonify(
            code_msg.REGISTER_SUCCESS.put('action', url_for('user.login')))
    verify_code = utils.generate_verify_code()
    session['verify_code'] = verify_code['answer']
    return render_template('user/register.html',
                           verify_code=verify_code['question'],
                           form=user_form)
Esempio n. 3
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegisterForm()
    if form.is_submitted():
        print(form.data)
        user = User.query.filter_by(username=form.username.data).first()
        if user:
            flash('That username is taken. Please choose a different one.',
                  'danger')
        else:
            hashed_password = bcrypt.generate_password_hash(
                form.password.data).decode('utf-8')
            user = User(username=form.username.data,
                        password=hashed_password,
                        is_active=False)
            db.session.add(user)
            db.session.commit()
            flash(
                'Account information submitted. Please wait for an admin to approve your account.',
                'info')
            return redirect(url_for('login'))
    return render_template('register.html', form=form, active='register')
Esempio n. 4
0
def user_reg():
    route_log()
    '''
    Route for user register page.
    '''
    '''Regular expressions to allow all latin characthers and remove two or more sequential spaces.'''
    text_regexp = '[^\u0041-\u005A\u0061-\u007A\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u024F\u1E00-\u1EFF ]'
    space_regexp = '\s{2,}'
    form = RegisterForm()
    if form.is_submitted() and form.validate() and form.submit.data:
        pythoncom.CoInitialize()
        fname = re.sub(space_regexp, "", re.sub(text_regexp, "", form.first_name.data))
        lname = re.sub(space_regexp, "", re.sub(text_regexp, "", form.last_name.data))
        if len(fname) == 0 or len(lname) == 0:
            msg = "Invalid input data in first or last name."
            pythoncom.CoUninitialize()
            data = "Failed user registration due to wrong input data in either fname or lname."
            res = build_log(data)
            print(res)
            return render_template("regRes.html", active=1, head_menu=app.config["head_menu"], title="Unsuccessful", msg=msg)
        while fname[-1] == " ": # Remove trailing spaces at the end
            fname = fname[0:-1]
        while lname[-1] == " ": # Remove trailing spaces at the end
            lname = lname[0:-1]
        user_data={
        "department": form.department.data,
        "role": form.role.data,
        "fname": fname,
        "lname": lname,
        "email": form.email.data,
        "passw": form.password.data
        }
        user_settings = win_user.create_user_settings(user_data)
        if not win_user.name_check(user_settings["sAMAccountName"]):
            msg = "Your username: "******"sAMAccountName"]  + " already exists in the Active Directory database. Please contact a system administrator."
            pythoncom.CoUninitialize()
            data = "User registration failed, username: "******"sAMAccountName"] + " alread in active directory!"
            res = build_log(data)
            print(res) # Print to log file
            return render_template("regRes.html", active=1, head_menu=app.config["head_menu"], title="Unsuccessful", msg=msg)
        #os.system("python \"" + win_user.path + "\" \"" + user_data["fname"] + " " + user_data["lname"] + "\" \"" + user_data['passw'] + "\" \"" + user_data['department'] + "\" \"" + user_data['role'] + "\" \"" + user_data['email'] + "\"")
        #os.system("python \"" + win_user.path + "\" \"" + user_data["fname"] + " " + user_data["lname"] + "\" \"" + user_data["department"] + "\"")
        #win_user.create_user(user_settings, user_data["passw"])
        try:
            ou = adcontainer.ADContainer.from_cn(user_data["department"].upper())
        except:
            msg = "An error occoured when getting the organizational unit from the Domain Controller."
            res = build_log(msg + " Make sure that OUs have the cn attributes set.")
            print(res) # Print to log file
            pythoncom.CoUninitialize()            
            return render_template("regRes.html", active=1, head_menu=app.config["head_menu"], title="Unsuccessful", msg=msg)
        try:
            user = aduser.ADUser.create(user_settings["sAMAccountName"], ou, user_data["passw"])
            time.sleep(1.5)
            #user = aduser.ADUser.from_cn(user_settings["sAMAccountName"])
            print("New User:\t" + str(aduser.ADUser.from_cn(user_settings['sAMAccountName'])))
        except:
            #print("Unable to get user from AD, user non existent.")
            msg = "An error occoured when creating the user account " + user_settings["sAMAccountName"] + ". If the problem persists, don't include your middle name. Max length is 20 characters including periods."
            res = build_log("An error occured when creating the user account: " + user_settings["sAMAccountName"])
            pythoncom.CoUninitialize()
            return render_template("regRes.html", active=1, head_menu=app.config["head_menu"], title="Unsuccessful", msg=msg)
        win_user.update_attributes(user_settings['sAMAccountName'], user_settings, user_data['passw'])
        win_user.join_group(user_settings['sAMAccountName'])
        pythoncom.CoUninitialize()
        res = build_log("New User created: " + user_settings["sAMAccountName"] + " created successfully.")
        print(res)
        msg = user_data["fname"] + ", your user account: " + user_settings["sAMAccountName"] + " should be created. If not please contact the system administrator."
        return render_template("regRes.html", active=1, head_menu=app.config["head_menu"], title="Succes", msg=msg)
    else:
        return render_template("user_reg.html", active=1, head_menu=app.config["head_menu"], form=form)