Example #1
0
def cardSignIn(eventUrl):
	db = get_db()
	eventsCol = db.events
	
	event = eventsCol.find_one({"url":eventUrl})
	
	if request.method == 'POST':
		db = get_db()
		usersCol= db.users
		
		ucsdIdInfo, ucsdIdNum = toNumAndInfo(request.form["ucsdId"])
		ucsdIdInfo += ucsdIdNum[1:4]
		ucsdIdInfoHash = hashInfo(ucsdIdInfo)

		
		userFromDb = usersCol.find_one({"ucsdIdInfo" : ucsdIdInfoHash})
		
		if(userFromDb):
			if(checkNum(ucsdIdNum, userFromDb["ucsdIdNum"])):
				if(userFromDb["access"]):
					if(not usersCol.find_one({"ucsdIdInfo" : ucsdIdInfoHash, "events.url": event["url"] })):
						usersCol.update_one({"ucsdIdInfo" : ucsdIdInfoHash}, {'$push': {"events":{"title": event["title"], "count": 1, "url":event["url"]}}})
					else:
						usersCol.update_one({"ucsdIdInfo" : ucsdIdInfoHash, "events.url": event["url"] },
					 	{'$inc': {"events.$.count": 1}})
					eventsCol.update_one({"url":eventUrl}, 
										{'$inc':{"participantCount": 1},})
					flash('Access granted!!')
				else:
					flash('Your access has been restricted!')
			else:
				flash('UCSD PID does not match our records. Contact the administrator for help.')
		else:
			flash('You are not registered!')
		return redirect(url_for('eventSignIn', eventUrl=event["url"]))
	
	
	if(event):
		eventPage = Page(event["title"] + " Sign-In", "<h3>Please sign-in using your UCSD ID card.</h3>")
		form = Form(event["title"] + " Sign-In", "eventSignIn", "Submit")
		form.setEventUrl(event["url"])
		form.addInput("PID:","password" , "ucsdId",autofocus="autofocus")
		eventPage.addForm(form)
		
		return render_template('form.html', page=eventPage)
	else:
		flash("Event does not exist, you can create one here.")
		return redirect(url_for('create_event'))
Example #2
0
def login():
    if session.get('logged_in'):
        return redirect(url_for('create_event'))
    
    error = None
    if request.method == 'POST':
        db = get_db()
    	usersCol = db.users
        
        userFromDb = usersCol.find_one({"ucsdEmail":request.form["ucsdEmail"]})
        
        if(not userFromDb):
            flash('Invalid email')
        else:
            password = request.form['password']
            matches = checkNum(password, userFromDb["password"])
        	
            if matches:
                session['logged_in'] = True
                session['admin'] = userFromDb["admin"]
                session['ucsdEmail'] = userFromDb["ucsdEmail"]
                flash('You were logged in')
                return redirect_dest(fallback=url_for('show_users'))
            else:
                flash('Invalid password')
                
   
    loginPage = Page("Login", "")
    
    form = Form("Login", "login", "Login")            
    form.addTextInput("UCSD Email", "ucsdEmail", placeholder="Your UCSD email...")
    form.addInput("Password", "password", "password", placeholder="Your password...")
    
    loginPage.addForm(form)
    
    return render_template('form.html', page=loginPage, redirect_login=request.args.get('next'))
Example #3
0
def register():
	"""Registers a user to the database."""
	
	registerPage = Page("Register", "")
	
	form = Form("Register", "register", "Register")
	
	form.addTextInput("First Name", "firstName", placeholder="Your first name...")
	form.addTextInput("Last Name", "lastName", placeholder="Your last name...")
	form.addTextInput("UCSD Email", "ucsdEmail", placeholder="Your UCSD email...")
	form.addInput("Password", "password", "password", placeholder="Your password...")
	form.addInput("Confirm Password", "password", "confirmPassword", placeholder="Your password again...")
	form.addTextInput("IEEE Member Number (Enter '0' if you don't have one.):", "ieeeNumber", placeholder="Your IEEE number...")
	
	majors = RadioSet("Major", "major")
	majors.addRadio("Electrical Engineering", "EE")
	majors.addRadio("Computer Engineering", "CE")
	majors.addRadio("Computer Science", "CS")
	majors.addRadio("Mechanical Engineering", "ME")
	
	form.addRadios(majors)
	
	studentType = RadioSet("Student Type", "studentType")
	studentType.addRadio("Non-Transfer (Entered as Freshman)", "nonTransfer")
	studentType.addRadio("Transfer", "transfer")
	studentType.addRadio("Graduate", "graduate")
	
	form.addRadios(studentType)
	
	years = RadioSet("Years", "years")
	years.addRadio("1st Year", "1")
	years.addRadio("2nd Year", "2")
	years.addRadio("3rd Year", "3")
	years.addRadio("4th Year", "4")
	years.addRadio("5th Year", "5")
	years.addRadio("6th Year", "6")
	
	form.addRadios(years)
	
	staffMember = RadioSet("Are you currently an IEEE Staff Member?", "staffMember")
	staffMember.addRadio("Yes", "yes")
	staffMember.addRadio("No", "no")
	
	form.addRadios(staffMember)
	
	registerPage.addForm(form)
	
	error = None
	if request.method == 'POST':
		db = get_db()
		userCol = db.users	
		userFromDb = userCol.find_one({"ucsdEmail" : request.form["ucsdEmail"]})
		
		if(userFromDb):
			flash("You already registered {}! Please continue to log in".format(userFromDb["firstName"]))
			return redirect(url_for('login'))
		else:
			
			passwordHash = None	
			if(request.form["password"] == request.form["confirmPassword"]):
				passwordHash = hashNum(request.form["password"])
			else:
				error="Passwords do not match."
				return render_template('form.html', error=error, page=registerPage)
		
			newUser = {
						"firstName" : request.form["firstName"],
						"lastName" : request.form["lastName"],
						"ucsdEmail" : request.form["ucsdEmail"],
						"password" : passwordHash,
						"admin" : False,
						"ieeeNumber" : request.form["ieeeNumber"],
						"major" : request.form["major"],
						"studentType" : request.form["studentType"],
						"years" : request.form["years"],
						"access" : True,
						"events" : []
			}
		
			userCol.insert_one(newUser)
		
			flash('You have been registered. Please login')
			return redirect(url_for('login'))
	
	return render_template('form.html', error=error, page=registerPage)
Example #4
0
def eventSignIn(eventUrl):
	db = get_db()
	eventsCol = db.events
	event = eventsCol.find_one({"url":eventUrl})
	
	
	#Event does not exist yet
	if(not event):
		flash("Event does not exist, you can create one here.")
		return redirect(url_for('create_event'))
		
	if request.method == 'POST':
		SALT = "$2b$12$voW9oQb/V53wOs9.YH3br."
		ucsdId = request.form["ucsdId"]
		ucsdIdHash = bcrypt.hashpw(ucsdId.encode('utf8'), SALT)
		
		usersCol = db.users
		
		userFromDb = usersCol.find_one({'ucsdId': ucsdIdHash})
		
		if (userFromDb is None):
			return redirect(url_for('projectSpaceRegistration', ucsdIdHash=ucsdIdHash))
		
		
		eventFromDb = eventsCol.find_one({'url':eventUrl})
					
		user = {
					"firstName": userFromDb["firstName"],
					"lastName": userFromDb["lastName"],
					"ucsdEmail": userFromDb["ucsdEmail"],
					"ieeeNumber": userFromDb["ieeeNumber"],
					"datetime": datetime.utcnow()
		}
	
		eventsCol.update_one(
								{"url": eventUrl}, 
								{
									'$inc': {"participantCount": 1},
									"$push": {
										"signins": user
									}
								}
							)
							
		flash("{}++ \n You are number {}!".format(user['firstName'],int(eventFromDb['participantCount'])+1))
		'''
		usersCol.update_one(
							{
								"ucsdEmail": ucsdEmail,
								"events.url": eventUrl
							},
							{
								"$set": {
											"events.$.status": "signedin"
										}
							}
						)
		
							
		try:
			userFromDb = usersCol.find_one({"ucsdEmail": session["ucsdEmail"]})
						
			user = {
						"firstName": userFromDb["firstName"],
						"lastName": userFromDb["lastName"],
						"ucsdEmail": userFromDb["ucsdEmail"],
						"ieeeNumber": userFromDb["ieeeNumber"],
						"datetime": datetime.utcnow()
			}
		
			eventsCol.update_one(
									{"url": eventUrl}, 
									{
										'$inc': {"participantCount": 1},
										"$push": {
											"signins": user
										}
									}
								)
			flash("Welcome {}, to {}.".format(user["firstName"], event["title"]))
		except (KeyError):
			flash("Unsuccesful sign-in")
		'''
		
	#Create page
	eventPage = Page(event["title"] + " Sign-In", "<h3>Please sign-in by swiping your UCSD ID card.</h3>")
	
	form = Form(event["title"] + " Sign-In", "eventSignIn", "Submit")
	form.setEventUrl(event["url"])
	form.addInput("UCSD ID Card","password" , "ucsdId", autofocus="autofocus", placeholder="UCSD ID Card..." )
	
	eventPage.addForm(form)
		
	return render_template('form.html', page=eventPage)
Example #5
0
def eventSignup(eventUrl):
	#Check if logged in
	if not session.get('ucsdEmail'):
		return redirect(url_for('login', next=request.endpoint, eventUrl=eventUrl))
	
	db = get_db()
	eventsCol = db.events
	event = eventsCol.find_one({"url":eventUrl})
	
	#Check if there is an event
	if(not event):
		flash("Event does not exist, you can create one here.")
		return redirect(url_for('create_event'))
	
	#Handles sign up request
	if(request.method == "POST"):
		event = {
					"count": 0,
					"url": eventUrl,
					"title": event["title"],
					"status": "signedUp"
		}
		
		usersCol = db.users
		usersCol.update_one(
							{"ucsdEmail": session["ucsdEmail"]},
							{"$push": {
										"events": event
									}
							}
							)
		userFromDb = usersCol.find_one({"ucsdEmail": session["ucsdEmail"]})
							
		user = {
					"firstName": userFromDb["firstName"],
					"lastName": userFromDb["lastName"],
					"ucsdEmail": userFromDb["ucsdEmail"],
					"ieeeNumber": userFromDb["ieeeNumber"],
					"datetime": datetime.utcnow()
		}
		
		eventsCol.update_one(
								{"url":eventUrl},
								{"$push": {
											"signups": user
										}
								}
							)
		flash("You have signed up for {}".format(event["title"]))
		return redirect(url_for('eventSettings', eventUrl=eventUrl))
	
	#Create page	
	signupPage = Page(event["title"], event["about"])
		
	form = Form("Sign Up", "eventSignup", "Sign Up")
	form.setEventUrl(eventUrl)
	
	experience = RadioSet("Experience with Project Space", "experience")
	experience.addRadio("No experience", 1)
	experience.addRadio("Some experience", 2)
	experience.addRadio("Very experienced", 3)
	
	form.addRadios(experience)
	
	signupPage.addForm(form)

	return render_template('form.html', page=signupPage)