Exemplo n.º 1
0
    def add_user_step2(self, username):
        try:
            print('Waiting for finger...')

            ## Wait that finger is read again
            while self.f.readImage() == False:
                pass

            ## Converts read image to characteristics and stores it in charbuffer 2
            self.f.convertImage(0x02)

            ## Compares the charbuffers
            if self.f.compareCharacteristics() == 0:
                return self.RESULT_FINGER_DO_NOT_MATCH

            ## Creates a template
            self.f.createTemplate()

            ## Saves template at new position number
            template_index = self.f.storeTemplate()
            logger.info(
                'Finger enrolled successfully. New template position #{}',
                str(template_index))

            ## save user in DB
            models.add_user(username, template_index, models.session_factory())
            return 0

        except Exception as e:
            logger.exception('Error while adding a user (step2).')
            return self.RESULT_ERROR
Exemplo n.º 2
0
def reset_db():
    Base.metadata.drop_all()
    Base.metadata.create_all()
    with open('MOCK_DATA.json') as f:
        mock = json.load(f)
    for i in mock:
        add_user(**i)
Exemplo n.º 3
0
def add_user():
    if not session.get('user'): return redirect('/')
    param = request.args if request.method == 'GET' else request.form
    username = param.get('username', '').strip()
    password = param.get('password', '').strip()
    groups = param.get('groups', '').strip()
    tel = param.get('tel', '').strip()
    email = param.get('email', '').strip()
    birthday = param.get('birthday', '').strip()
    age = param.get('age', '').strip()
    sex = param.get('sex', '').strip()
    dept = param.get('dept', '').strip()
    hobby_l = ' | '.join(param.getlist('hobby'))
    #hobby_l=str(param.getlist('hobby'))
    bz = param.get('bz', '').strip()

    OK, error = models.same_user(username, password, age, sex)
    if OK:
        models.add_user(username, password, groups, tel, email, birthday,
                        int(age), int(sex), dept, hobby_l, bz)
        return redirect('/users/')
    else:
        return render_template('/user_add.html/',
                               error=error,
                               username=username,
                               password=password,
                               groups=groups,
                               tel=tel,
                               email=email,
                               birthday=birthday,
                               age=age,
                               sex=sex,
                               dept=dept,
                               bz=bz)
Exemplo n.º 4
0
def index_post():
    user = users.get_current_user()
    if user:
        yandex_token = request.form['yandex_token']
        device_token = request.form['device_token']
        device_address = request.form['device_address']
        device_address = device_address.replace('http://', '').replace(
            'https://', '').replace('wss://', '')
        if not ':' in device_address:
            device_address += ':1961'

        case1step1 = request.form['case1step1']
        case1step2 = request.form['case1step2']
        case1step3 = request.form['case1step3']

        case2step1 = request.form['case2step1']
        case2step2 = request.form['case2step2']
        case2step3 = request.form['case2step3']

        models.add_user(user.email(), yandex_token, device_token,
                        device_address, [case1step1, case1step2, case1step3],
                        [case2step1, case2step2, case2step3])

        return '<html><body>Data successfully saved</body></html>'
    else:
        return ''
Exemplo n.º 5
0
def register():
    username = request.form.get('username', '')
    password = request.form.get('password', '')
    email = request.form.get('email', '')
    if models.exist_user(username, email):
        models.add_user(username, password, email)
        return redirect('/')
    else:
        return render_template('index.html', registererror="用户或邮箱已被注册")
Exemplo n.º 6
0
def register():
    username = request.form.get('username', '')
    password = request.form.get('password', '')
    email = request.form.get('email', '')
    if models.exist_user(username, email):
        models.add_user(username, password, email)
        return redirect('/')
    else:
        return render_template('index.html', registererror="用户或邮箱已被注册")
Exemplo n.º 7
0
def store_new_user():
    "Accepts POST request of new user"

    first_name = request.form['first-name']
    last_name = request.form['last-name']
    image_url = request.form['image-url']

    add_user(first_name, last_name, image_url)

    flash(f"{first_name} {last_name} was added as a user.")
    return redirect('/users')
Exemplo n.º 8
0
def register():
    username = request.form.get('username','')
    password = request.form.get('password','')
    age = request.form.get('age','')
    address = request.form.get('address','')
    ok,info = models.validate_user_add(username,password,age,address)
    if ok:
    	models.add_user(username,password,age,address)
    	info = '注册成功'

    return render_template('index.html',registerok=ok,registerinfo=info)
Exemplo n.º 9
0
def update_transcript():
    if request.method == 'POST':
        file = request.files['transcript']
        netid = session['netid'] if 'netid' in session else None
        if file and netid:
            studentinfo = parse_transcript(file)
            if studentinfo != None:
                add_user(studentinfo,session['netid'],True)
        if studentinfo == None:
            return json.dumps({'status':'OK','correctfile':'No'})
        else:
            return json.dumps({'status':'OK','correctfile':'Yes'})
Exemplo n.º 10
0
def page_register():
    if current_user.is_authenticated:
        return redirect(url_for('page_task'))
    if request.method == 'POST':
        eml = request.form.get('eml')
        psw1 = request.form.get('psw1')
        psw2 = request.form.get('psw2')
        result = validate_user([eml, psw1, psw2], 'reg')
        flash(result)
        if result == 'OK':
            add_user(eml, psw1)
            return redirect(url_for('page_login'))
    return render_template('register.html')
Exemplo n.º 11
0
def adduser():
    username = request.form.get('username', '')
    password = request.form.get('password', '')
    email = request.form.get('email', '')
    if models.exist_user(username, email):
        models.add_user(username, password, email)
        ok = True
        result = "添加成功"
        return json.dumps({'ok': True, 'result': result})
    else:
        ok = False
        result = "添加失败"
        return json.dumps({'ok': False, 'result': result})
Exemplo n.º 12
0
def fill_db():
    with open('MOCK_POSTS.json') as f:
        mock_posts = json.load(f)
    with open('MOCK_USERS.json') as f:
        mock_users = json.load(f)
    
    usernames = []
    for user in mock_users:
        usernames.append(user['name'])
        add_user(**user)

    for post in mock_posts:
        add_post(username=choice(usernames), **post)
Exemplo n.º 13
0
def adduser():
    username = request.form.get('username', '')
    password = request.form.get('password', '')
    email = request.form.get('email', '')
    if models.exist_user(username,email):
        models.add_user(username,password,email)
        ok = True
        result = "添加成功"
        return json.dumps({'ok' : True,'result':result})
    else:
        ok = False
        result = "添加失败"
        return json.dumps({'ok': False,'result':result})
Exemplo n.º 14
0
 def confirm_cancel_modify(self):
     data = "******************************\n\r Name : {}\n\r " \
            "Phone : {}\n\r Email : {}\n\r Booking Table Type : " \
            "{}\n\r Seating Capacity : {}\n\r Booking Time " \
            "(IST 24.Hr) : {}\n\r Booking Meal Type : {}\n\r***" \
            "***************************".format(
             self.user_name.title(), self.user_phone,
             self.user_email, self.book_table_type.title(),
             self.book_table_number, self.booking_time,
             self.book_meal_type
             )
     if not self.confirm_booking:
         log.info("Confirm booking not set")
         self.sender.sendMessage("Summary Of Booking")
         self.sender.sendMessage(data)
         keyboard = InlineKeyboardMarkup(inline_keyboard=[
             [
                 InlineKeyboardButton(
                     text='Confirm Booking',
                     callback_data=self.confirm_booking_type[0])
             ],
             [
                 InlineKeyboardButton(
                     text='Cancel Booking',
                     callback_data=self.cancel_booking_type[0])
             ],
             [
                 InlineKeyboardButton(
                     text='Modify Booking',
                     callback_data=self.modify_booking_type[0])
             ],
         ])
         self.sender.sendMessage('Please Confirm/Cancel/Modify Booking',
                                 reply_markup=keyboard)
     else:
         log.info("Confirm booking is set send email")
         send_email(self.user_email, self.user_name,
                    data.replace('\n\r', '<br>'))
         self.sender.sendMessage("Email Sent Successfully to: {}"
                                 "".format(self.user_email))
         add_user(self.client,
                  user_id=self.user_id,
                  name=self.user_name,
                  email=self.user_email,
                  created_on=self.user_timestamp,
                  phone=self.user_phone,
                  table_type=self.book_table_type,
                  table_number=self.book_table_number,
                  booking_time=self.booking_time,
                  meal_type=self.book_meal_type)
         self.confirm_booking = False
Exemplo n.º 15
0
    def test_user_consecutive_login(self):
        models.add_user("Alice", 0, self.session)

        # consecutives log in
        user1 = models.get_user_by_template(0, self.session)
        r = models.add_login(user1, self.session)
        self.assertEqual(True, r)
        actions = self.session.query(models.UserAction).all()
        self.assertEqual(len(actions), 1)

        user1 = models.get_user_by_template(0, self.session)
        r = models.add_login(user1, self.session)
        self.assertEqual(False, r)
        actions = self.session.query(models.UserAction).all()
        self.assertEqual(len(actions), 1)
Exemplo n.º 16
0
def index():
    if request.method == 'POST':
        name = request.form['name']
        email = request.form['email']
        password = request.form['password']
        password_check = request.form['password_check']
        if password != password_check:
            return render_template('index.html', error='passwords_dont_match')
        try:
            add_user(name, email, password)
        except AccountExists:
            return render_template('index.html', error='account_already_exists')
        session['account'] = name
        return redirect('/users/' + name)
    return render_template('index.html')
Exemplo n.º 17
0
def index():
    if request.method == "POST":
        name = request.form['name']
        email = request.form['email']
        password = request.form['password']
        password_check = request.form['password_check']
        if password != password_check:
            return render_template('index.html', error="passwords_not_match")
        try:
            add_user(name, email, password)
        except IntegrityError:
            return render_template('index.html', error='already_exists')
        session['username'] = name
        return redirect(url_for('user_page', name=name))
    return render_template('index.html')
Exemplo n.º 18
0
def populate_users():
    """Create minimum sample data for the user table."""

    users = [{
        'username': '******',
        'email': 'mary @ example.com'
    }, {
        'username': '******',
        'email': 'john @ example.com'
    }, {
        'username': '******',
        'email': ADMIN_EMAIL
    }]
    for user in users:
        add_user(username=user['username'], email=user['email'])
Exemplo n.º 19
0
	def post(self):
		username = self.request.get('username')
		email = self.request.get('email')
		password = self.request.get('password')
		try:
			user = models.add_user(username, email, password)
			self.redirect_to_user_home(user)
			self.response.set_cookie('userlogin', user.login,
				max_age=10*365*24*60*60, overwrite=True)
		except models.UserExistsException:
			variables = {
				'message': 'usuário já existe'.decode('utf-8'),
				'username': username,
				'email': email
			}
			template = JINJA_ENVIRONMENT.get_template('signup.html')
			self.response.write(template.render(variables))
		except models.EmailExistsException:
			variables = {
				'message': 'email já existe'.decode('utf-8'),
				'username': username,
				'email': email
			}
			template = JINJA_ENVIRONMENT.get_template('signup.html')
			self.response.write(template.render(variables))
Exemplo n.º 20
0
def register():
    # 从request.form中获取username、password、telephone信息
    username = request.form.get('username', '')
    password = request.form.get('password', '')
    telephone = request.form.get('telephone', '')
    age = request.form.get('age', '')

    # 检查用户提交的数据
    ok, result = models.validate_user_add(username, password, telephone, age)

    # 如果检查通过则添加到文件中
    if ok:
        if models.add_user(username, password, telephone, age):
            ok = True
            result = '注册成功'
        else:
            ok = False
            result = '注册失败'

    return render_template('login.html',
                           ok=ok,
                           result=result,
                           register_username=username,
                           password=password,
                           telephone=telephone,
                           age=age)
Exemplo n.º 21
0
def register():
    username =  request.form.get('username','')
    password =  request.form.get('password','')
    age = request.form.get('age','')
    address = request.form.get('address','')
    ok,info =  models.validate_user_register(username,password,age,address)
    if ok:
        models.add_user(username,password,age,address)
        validate = models.validate_user_login(username,password)
        if validate:
            info = '恭喜您,注册成功'
        else:
	    info = '注册失败了'
        return render_template('/index.html',registerok=ok, registerinfo=info)
    else:
        return render_template('/index.html',registerok=ok, registerinfo=info,usernameinfo = username,passwordinfo = password,ageinfo = age,addressinof = address)
Exemplo n.º 22
0
    def test_user_consecutive_logout(self):
        models.add_user("Alice", 0, self.session)

        user1 = models.get_user_by_template(0, self.session)
        models.add_login(user1, self.session)

        user1 = models.get_user_by_template(0, self.session)
        r = models.add_logout(user1, self.session)
        self.assertEqual(0, r)
        actions = self.session.query(models.UserAction).all()
        self.assertEqual(2, len(actions))

        user1 = models.get_user_by_template(0, self.session)
        r = models.add_logout(user1, self.session)
        self.assertEqual(2, r)
        actions = self.session.query(models.UserAction).all()
        self.assertEqual(2, len(actions))
Exemplo n.º 23
0
    def test_user_no_previous_login_by_logout(self):
        user1 = models.add_user("Alice", 0, self.session)

        user1 = models.get_user_by_template(0, self.session)
        r = models.add_logout(user1, self.session)
        self.assertEqual(1, r)
        actions = self.session.query(models.UserAction).all()
        self.assertEqual(0, len(actions))
Exemplo n.º 24
0
    def post(self):
        """Request data needed for create"""
        data = request.get_json()
        result = add_user(data)

        response = jsonify({'id': str(result.inserted_id)})
        response.status_code = 201
        return response
Exemplo n.º 25
0
def add_user():
    new_user = {}
    param = request.args if request.method == 'GET' else request.form
    new_user['username'] = param.get('username', '').strip()
    new_user['password'] = param.get('password', '').strip()
    new_user['group'] = param.get('group', '').strip()
    new_user['tel'] = param.get('tel', '').strip()
    result = models.same_user(new_user.get('username'))
    if result:
        return render_template('/user_add.html/',
                               error='Same name erro.',
                               username=new_user.get('username'),
                               password=new_user.get('password'),
                               group=new_user.get('group'),
                               tel=new_user.get('tel'))
    else:
        models.add_user(new_user)
        return redirect('/users/')
Exemplo n.º 26
0
def register_user():

    if "user" in session:
        flash("Please log out prior to registration")
        return redirect('/dashboard')

    fname = request.form.get('fname').rstrip()
    lname = request.form.get('lname').rstrip()
    email = request.form.get('email').rstrip()
    pw_hash = bcrypt.generate_password_hash(request.form.get('password'))

    if User.query.filter_by(email=email).first():
        flash("This email has already been registered")
        return redirect('/register')

    else:
        match_obj = re.search(
            r"(^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$)", email)

        if match_obj:
            user = add_user(email, pw_hash, fname, lname)

            gmail_user = os.environ['MAIL_USERNAME']
            gmail_password = os.environ['MAIL_PASSWORD']

            sender = gmail_user
            to = user.email

            subject = "[Welcome to Koi] Account Confirmation"

            token = ts.dumps(user.email, salt='email-confirm-key')

            confirm_url = url_for('confirm_email', token=token, _external=True)

            body = """Your account was successfully created. Please verify your email within 24 hours. Click the link below to confirm your email address and activate your account:\n{}\nQuestions? Comments? Fill out feedback at https://koirewards.herokuapp.com/.\n- Koi Team :)""".format(
                confirm_url)

            msg = 'Subject: {}\n\n{}'.format(subject, body)

            try:
                server = smtplib.SMTP_SSL('smtp.gmail.com', 465)
                server.ehlo()
                server.login(gmail_user, gmail_password)
                server.sendmail(sender, to, msg)
                server.close()
            except:
                print 'Something went wrong...'

            flash(
                "A confirmation email has been sent! Please verify your account."
            )
            return redirect("/")

        else:
            flash("Please enter a valid email.")
            return redirect('/register')
Exemplo n.º 27
0
def register():

    username = request.form.get('username', '')

    password = request.form.get('password', '')

    age = request.form.get('age', '')

    address = request.form.get('address', '')

    ok, info = models.validate_user_add(username, password, age, address)

    if ok:

        models.add_user(username, password, age, address)

        info = '注册成功'

    return render_template('index.html', registerok=ok, registerinfo=info)
Exemplo n.º 28
0
def save():
    # Retrieve the HTTP POST request parameter value from 'request.form' dictionary

    username = request.form.get('username')
    password = request.form.get('password')

    response = add_user(username, password)

    if response:
        return render_template('login.html')
    else:
        return 'Unable to signup', 400  # 400 Bad Request
Exemplo n.º 29
0
    def test_user_action_operations(self):

        models.add_user("Alice", 0, self.session)
        models.add_user("Bob", 1, self.session)
        models.add_user("Peter", 2, self.session)

        user1 = models.get_user_by_template(0, self.session)
        models.add_login(user1, self.session)

        user2 = models.get_user_by_template(1, self.session)
        models.add_login(user2, self.session)

        user2 = models.get_user_by_template(1, self.session)
        models.add_logout(user2, self.session)

        user3 = models.get_user_by_template(2, self.session)
        models.add_login(user3, self.session)
        user3 = models.get_user_by_template(2, self.session)
        models.add_logout(user3, self.session)

        user1 = models.get_user_by_template(0, self.session)
        models.add_logout(user1, self.session)

        actions = self.session.query(models.UserAction).all()
        self.assertEqual(len(actions), 6)

        models.truncate_user_actions(self.session)
        actions = self.session.query(models.UserAction).all()
        self.assertEqual(len(actions), 0)

        self.session.close()
Exemplo n.º 30
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        email = form.email.data
        password = form.password.data
        success = add_user(email, password)
        if success:
            flash('Thanks for registering')
            return redirect(url_for('login'))
        else:
            flash('User already exist')

    return render_template('register.html', form=form, title="Register")
Exemplo n.º 31
0
def register():
    username = request.form.get('username', '')
    password = request.form.get('password', '')
    age = request.form.get('age', '')
    address = request.form.get('address', '')
    ok, info = models.validate_user_register(username, password, age, address)
    if ok:
        models.add_user(username, password, age, address)
        validate = models.validate_user_login(username, password)
        if validate:
            info = '恭喜您,注册成功'
        else:
            info = '注册失败了'
        return render_template('/index.html', registerok=ok, registerinfo=info)
    else:
        return render_template('/index.html',
                               registerok=ok,
                               registerinfo=info,
                               usernameinfo=username,
                               passwordinfo=password,
                               ageinfo=age,
                               addressinof=address)
Exemplo n.º 32
0
def add_user_json():
    if not session.get('user'): return redirect('/')
    param = request.args if request.method == 'GET' else request.form
    username = param.get('username', '').strip()
    password = param.get('password', '').strip()
    groups = param.get('groups', '').strip()
    tel = param.get('tel', '').strip()
    email = param.get('email', '').strip()
    birthday = param.get('birthday', '').strip()
    age = param.get('age', '').strip()
    sex = param.get('sex', '').strip()
    dept = param.get('dept', '').strip()
    hobby_l = ' | '.join(param.getlist('hobby'))
    #hobby_l=str(param.getlist('hobby'))
    bz = param.get('bz', '').strip()

    OK, error = models.same_user(username, password, age, sex)
    if OK:
        models.add_user(username, password, groups, tel, email, birthday,
                        int(age), int(sex), dept, hobby_l, bz)
        return json.dumps({'code': 200})
    else:
        #return json.dumps({'code':400,'error':error})
        return json.dumps({
            'code': 400,
            'error': error,
            'username': username,
            'password': password,
            'groups': groups,
            'tel': tel,
            'email': email,
            'birthday': birthday,
            'age': age,
            'sex': sex,
            'dept': dept,
            'bz': bz
        })
Exemplo n.º 33
0
def register_handle():
    form=RegisterForm(request.form)
    if request.method=="POST" and form.validate():
        stat = check_user(request.form['username'])
        if stat==True:
            flash("This username already taken")
            return redirect(url_for("register_handle"))
        else:

            username=request.form['username']
            email =request.form['email']
            password= request.form['pswd']
            first_name =request.form['firstname']
            last_name = request.form['lastname']
            print("dfghjkl")
            print("fffff",username, password, email, first_name, last_name)
            add_user(password,username,email,first_name,last_name)

            flash("welcome"+username)
            session['logged_in'] = True
            session['username'] = username
            return redirect(url_for("dashboard"))

    return render_template("register.html", form=form)
Exemplo n.º 34
0
def register():
    # 从request.form中获取username、password、telephone信息
    username = request.form.get('username', '')
    password = request.form.get('password', '')
    telephone = request.form.get('telephone', '')

    # 对用户唯一性,手机号正确性检查
    ok, result = models.validate_user_add(username, password, telephone)
    
    # 如果检查通过则添加到文件中
    if ok:
        if models.add_user(username, password, telephone):
            ok = True
            result = '注册成功'
        else:
            ok = False
            result = '注册失败'

    return render_template('login.html', ok=ok, result=result, register_username=username, password=password, telephone=telephone)
Exemplo n.º 35
0
def register():
	name = request.form.get('username', '')
	password = request.form.get('password', '')
	telephone = request.form.get('telephone', '')
	age = request.form.get('age', '')

	# models.validate_user_add返回(True,'')或者('False',原因)
	ok, result = models.validate_user_add(name, password, telephone, age)

	if ok:
		# models.add_user的返回值会与0比较,返回True或者False
		if models.add_user(name, password, telephone, age):
			ok = True
			result = u'注册成功'
		else:
			ok = False
			result = u'注册失败'

	return render_template('login.html', ok=ok, result=result, username=name, 
		password=password, telephone=telephone, age=age)
Exemplo n.º 36
0
def addUser():
	name = request.form.get('username', '')
	password = request.form.get('password', '')
	telephone = request.form.get('telephone', '')
	age = request.form.get('age', '')

	ok, result = models.validate_user_add(name, password, telephone, age)

	if ok:
		if models.add_user(name, password, telephone, age):
			ok = True
			result = u'注册成功'
		else:
			ok = False
			result = u'注册失败'
	if ok:
		return redirect(url_for('listUser'))
	else:
		return render_template('create.html', result=result, username=name, 
			password=password, telephone=telephone, age=age)
Exemplo n.º 37
0
def signup_handler():
    form = SignupForm()
    if form.validate_on_submit():
        name = form.name.data
        email = form.email.data
        password = form.password.data
        confirm_password = form.password_conf.data
        if password != confirm_password:
            return '<h1>Password do not match!</h1>'
        hashed_pwd = bcrypt.hashpw(password.encode('utf8'),
                                   bcrypt.gensalt())  # Hash Password with salt
        if bcrypt.checkpw(password.encode('utf8'), hashed_pwd):
            res = models.add_user(email, name, hashed_pwd)  # Add user to DB
        if res:
            session['email'] = email  # Add email and name to session object
            session['name'] = name
            return redirect(url_for('home'))
        else:
            return redirect(url_for('login_handler'))

    return render_template('signup.html', form=form)
Exemplo n.º 38
0
def addUser():
    # 从request.form中获取username、password、telephone信息
    username = request.form.get('username', '')
    password = request.form.get('password', '')
    telephone = request.form.get('telephone', '')
    age = request.form.get('age', '')

    # 检查用户提交的数据
    ok, result = models.validate_user_add(username, password, telephone, age)
    
    # 如果检查通过则添加到文件中
    if ok:
        if models.add_user(username, password, telephone, age):
            ok = True
            result = '注册成功'
        else:
            ok = False
            result = '注册失败'
    if ok:
        return redirect('/users/')
    else:
        return render_template('create.html',  result=result, register_username=username, password=password, telephone=telephone, age=age)
Exemplo n.º 39
0
def register():
    # 从request.form中获取username、password、telephone信息
    username = request.form.get("username", "")
    password = request.form.get("password", "")
    telephone = request.form.get("telephone", "")
    age = request.form.get("age", "")

    # 检查用户提交的数据
    ok, result = models.validate_user_add(username, password, telephone, age)

    # 如果检查通过则添加到文件中
    if ok:
        if models.add_user(username, password, telephone, age):
            ok = True
            result = "注册成功"
        else:
            ok = False
            result = "注册失败"

    return render_template(
        "login.html", ok=ok, result=result, register_username=username, password=password, telephone=telephone, age=age
    )
Exemplo n.º 40
0
def upload_file():
    mistake = False
    if request.method == 'GET' or request.method == 'HEAD':
        if LOCALHOST: 
            nid = '' # fill in your netid
        else:
            ticket_from_cas = request.args.get('ticket')
            nid = C.Authenticate2(ticket_from_cas)
            if nid == "" or None:
               nid = session['netid'] if 'netid' in session else None
            if nid == "" or None:
               loginpage = C.Authenticate1()
               return redirect(loginpage)
        session['netid'] = nid
        netid = search_users(nid)
        if netid:
            info = get_student_info(netid)

            ret = get_progress(netid)
            ret_certs = get_progress_certificates(netid)

            majors_completed,doublecountcom = get_major_by_courses(ret)
            majors_gpa,doublecountgpa = get_major_by_gpa(ret)
            certificates_completed,doublecountcerts = get_major_by_courses(ret_certs)

            major_interests,certificate_interests = get_major_certificate_interests(netid)

            # get info of courses for interested majors/certificates
            majors_of_interest = []
            certificates_of_interest = []
            major_names = []
            certificate_names = []
            for maj in majors_completed:
                major_names.append(maj[0])
                if maj[0] in major_interests:
                    majors_of_interest.append(maj)
            for cert in certificates_completed:
                certificate_names.append(cert[0])
                if cert[0] in certificate_interests:
                    certificates_of_interest.append(cert)

            requirements_dictionary = get_major_cert_requirements(major_names,certificate_names)

            simple_dc = []
            for dc in doublecountcom:
                simple_dc.append(dc[0])
            for dc in doublecountgpa:
                simple_dc.append(dc[0])
            for dc in doublecountcerts:
                simple_dc.append(dc[0])

            d = {
                'netid': netid,
                'majors_completed': majors_completed,
                'majors_gpa': majors_gpa,
                'certificates_completed': certificates_completed,
                'interested_majors': majors_of_interest,
                'interested_certificates': certificates_of_interest,
                'int_majors': major_interests,
                'int_certificates': certificate_interests,
                'doublecount': simple_dc,
                'info': info,
                'reqs_dict':requirements_dictionary
            }
            return render_template('success_bs.html',d=d)
    if request.method == 'POST':
        file = request.files['transcript']
        studentname = request.form['Name']
        degree = request.form['Degree']
        major = request.form['Major']
        manualcourses = request.form['manual_courses']
        netid = session['netid'] if 'netid' in session else None
        if netid is None:
            loginpage = C.Authenticate1()
            return redirect(loginpage)
        if file:
            studentinfo = parse_transcript(file)
            if studentinfo == None:
                mistake = True          
        if not mistake and (file or manualcourses):
            if not file and manualcourses:
                if studentname == "":
                    studentname == "Anonymous Tiger"
                course_manual_parsed = parse_manual_courses(manualcourses)
                # since we do not know how many pdfs, set to -1
                studentinfo = [studentname,degree,major,course_manual_parsed,-1]
            if add_user(studentinfo,netid,False) != None:

                info = [studentinfo[0],studentinfo[1],studentinfo[2],studentinfo[4]]

                ret = get_progress(netid)
                ret_certs = get_progress_certificates(netid)

                majors_completed,doublecountcom = get_major_by_courses(ret)
                majors_gpa,doublecountgpa = get_major_by_gpa(ret)
                certificates_completed,doublecountcerts = get_major_by_courses(ret_certs)

                major_interests,certificate_interests = get_major_certificate_interests(netid)
                
                majors_of_interest = []
                certificates_of_interest = []
                major_names = []
                certificate_names = []
                for maj in majors_completed:
                    major_names.append(maj[0])
                    if maj[0] in major_interests:
                        majors_of_interest.append(maj)
                for cert in certificates_completed:
                    certificate_names.append(cert[0])
                    if cert[0] in certificate_interests:
                        certificates_of_interest.append(cert)

                requirements_dictionary = get_major_cert_requirements(major_names,certificate_names)

                simple_dc = []
                for dc in doublecountcom:
                    simple_dc.append(dc[0])
                for dc in doublecountgpa:
                    simple_dc.append(dc[0])
                for dc in doublecountcerts:
                    simple_dc.append(dc[0])

                d = {
                    'netid': netid,
                    'majors_completed': majors_completed,
                    'majors_gpa': majors_gpa,
                    'certificates_completed': certificates_completed,
                    'interested_majors': majors_of_interest,
                    'interested_certificates': certificates_of_interest,
                    'int_majors': major_interests,
                    'int_certificates': certificate_interests,
                    'doublecount': simple_dc,
                    'info': info,
                    'reqs_dict':requirements_dictionary
                }
                return render_template('success_bs.html',d=d)
    d = { 
        'mistake':mistake
    }
    return render_template('index_bs.html',d=d)
Exemplo n.º 41
0
def add_user(userid,name,email,phone):
     result = models.add_user(sql_db,userid,name,email,phone)
     return jsonify(result)