Esempio n. 1
0
def setup_admin():
    """Setup Admin Credentials that will be used to view Scoreboard"""
    admin_email = str(input("Enter Email Address for Admin : "))
    admin_password = str(input("Enter Password for Admin : "))
    admin_password_hashed = bcrypt.generate_password_hash(admin_password).decode(
        "utf-8"
    )
    admin = users(
        email=admin_email,
        password=admin_password_hashed,
        name="admin",
        phno=0000000000,
        clgname="None",
        quiz_name=0,
        timeleft=0,
        admin=True,
    )

    try:
        db.session.add(admin)
        db.session.commit()
        print("Done. Login and you'll be redirected to Scoreboard")
    except Exception as e:
        print("Some error Occured")
        print(e)
        db.session.rollback()
Esempio n. 2
0
def register():
    form = registerform()
    if request.method == 'POST':
        username = request.form['username']
        password = (request.form['password'])
        password = generate_password_hash(password,
                                          method='pbkdf2:sha256',
                                          salt_length=8)
        firstname = request.form['firstname']
        lastname = request.form['lastname']
        email = request.form['email']
        location = request.form['location']
        biography = request.form['biography']
        profile_picture = form.profile_picture.data
        filename = secure_filename(profile_picture.filename)
        profile_picture.save(
            os.path.join(app.config['UPLOAD_FOLDER'], filename))
        join_on = date.today()
        newuser = users(username, password, firstname, lastname, email,
                        location, biography, filename, join_on)
        db.session.add(newuser)
        db.session.commit()
        return jsonify({"message": "new user success fully made"})

    errors = form_errors(form)
    return jsonify({"errors": errors})
Esempio n. 3
0
def register():
	if current_user.is_authenticated:
		return redirect(url_for('index'))
	form = RegistrationForm()
	if form.validate_on_submit():
		otp_num = random.randint(1000,9999)
		hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
		user = users(username = form.username.data,name = form.name.data,gender = form.gender.data,phoneNo = form.phoneNo.data,dob = form.dob.data,
		email = form.email.data,govtid = form.govtId.data,password = hashed_password,otpuser=otp_num)
		email = form.email.data
		user_name= form.username.data
		token = s.dumps(email, salt='email-confirm')
		msg = Message('Confirm Email', sender = '*****@*****.**',recipients=[email])
		link = url_for('confirm_email',token = token, _external = True)
		msg.body = 'Your link is {}'.format(link)
		mail.send(msg)
		#otp_num = random.randint(1000,9999)
		#token1 = s.dumps(otp_num, salt='otp-confirm')
		msg_otp = Message('Confirm OTP', sender = '*****@*****.**',recipients=[email])
		#link_otp = url_for('confirm_otp',token = otp_num, _external = True)
		msg_otp.body = 'Your otp is {}'.format(otp_num)
		mail.send(msg_otp)
		
		#check_otp = url_for('confirm_otp',user=user)
		#otp1 = otp(otp = otp_num)
		#db.session.add(otp1)
		db.session.add(user)
		db.session.commit()
		#flash('Your account has now been created.. You can now log in !!','success')
		#return redirect(url_for('login'))
	
		return render_template('otp.html',user_name=user_name,title = 'Verification',form=form)
	return render_template('register.html',title = 'Register',form=form)	
Esempio n. 4
0
def create_user():
    username = str(input("Enter usename : "))
    name = str(input("Enter Name : "))
    email = str(input("Enter email address : "))
    password = str(input("Enter a password : "))
    hashed_password = bcrypt.generate_password_hash(password).decode('utf-8')
    user = users(username=username,
                        name=name,
                        email=email,
                        password=hashed_password)
    db.session.add(user)
    db.session.commit()
    print('User created. Now you can login.')
Esempio n. 5
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = users(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        app.logger.info('New user registered: %s' % user.username)
        flash(_('You have successfully been registered.'))
        return redirect(url_for('login'))
    return render_template('register.html', title=_('Register'), form=form)
Esempio n. 6
0
def test_init():
    user = models.users.query.filter_by(username='******').first()
    if user is None:
        user = models.users(username='******',
                            password='******',
                            catagory='administrator')
        try:
            db.session.add(user)
            db.session.commit()
            return 'User(%s) create success' % user.username
        except Exception as e:
            return 'User(%s) create failed: %s' % (user.username, str(e))
    else:
        return 'User has already created'
Esempio n. 7
0
def adduser(req):
    if req.method == "POST":
        forms = AddUserForm(req.POST)
        if forms.is_valid():
            username = forms.cleaned_data['username']
            permissions = forms.cleaned_data['permissions'] 
            try:
                add_user = users() 
                add_user.username = username
                add_user.permission = permissions
                add_user.save()
                data = json.dumps({'status': '200'})
                return HttpResponse(data)
            except Exception, e:
                data = json.dumps({'status': '500', 'err': e})
                return HttpResponse(data)
        else:
            data = json.dumps({'status': '502', 'forms': u'格式输入有误~'})
            return HttpResponse(data)
Esempio n. 8
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode("utf-8")
        event = events.query.filter_by(id=form.quiz.data).first()
        user_login = users(
            email=form.email.data,
            name=form.name.data,
            clgname=form.clgname.data,
            phno=str(form.phno.data),
            password=hashed_password,
            quiz_name=form.quiz.data,
            timeleft=event.time,
        )
        try:
            db.session.add(user_login)
            db.session.commit()
            flash("Signed up successfully.")
            next = request.args.get("next")
            socketio.emit(
                "stats_updated",
                {
                    "user_id": user_login.user_id,
                    "name": user_login.name,
                    "phno": user_login.phno,
                    "clgname": user_login.clgname,
                    "score": user_login.score,
                },
                namespace="/leaderboard/{}".format(event.event_name),
            )
            return redirect(next or url_for("user.login"))
        except Exception as e:
            print(e)
            db.session.rollback()
    else:
        print(form.errors)
    return render_template("register.html", form=form)
Esempio n. 9
0
def signup():
    form = SignUpForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        auth_code = form.auth_code.data
        if (auth_code == app.config['AUTH_CODE']):
            user = users(username=form.username.data,
                         name=form.name.data,
                         email=form.email.data,
                         password=hashed_password)
            db.session.add(user)
            db.session.commit()
            flash('Your account has been created! You are now able to log in',
                  'success')
            return redirect(url_for('user.login'))
        else:
            flash(
                'Invalid Authentication Code !  Contact Technical Secretaries or Developers.'
            )
    else:
        print(form.errors)
    return render_template('signup.html', title='Sign Up', form=form)