Ejemplo n.º 1
0
def getUserData(email):
    dbRet = database_helper.getUser(email)
    if (dbRet == []):
        return jsonify(success = False, message = "User does not exist")
    else:
        dbRet[0] = dbRet[0][:1] + dbRet[0][2:]
        return jsonify(success = True, message = "Got user data", data = dbRet[0])
Ejemplo n.º 2
0
def getUserData(email):
    dbRet = database_helper.getUser(email)
    if not dbRet:
        return jsonify(success=False, message="User does not exist")
    else:
        # dbRet[0] = dbRet[0][:1] + dbRet[0][2:]
        del dbRet["password"]
        return jsonify(success=True, message="Got user data", data=dbRet)
Ejemplo n.º 3
0
def signIn():
	#Authenticates user, returns string containing random generated token
	email = request.form['email']
	password = request.form['password']
	user = database_helper.getUser(email)
	if user == None:
		return json.dumps({'success' : False, 'message' : 'no such user'})
	elif verifyPass(password, user[1]):
		token =''.join([random.choice(string.ascii_letters + string.digits) for n in xrange(32)])
		loggedInUsers[token] = email
		return json.dumps({'success' : True, 'message' : 'you logged in', 'data':token})
	else:
		return json.dumps({'success' : False, 'message' : 'wrong password'})
Ejemplo n.º 4
0
def changePassword():
    token = request.form['token']
    oldPassword = hashlib.sha224(request.form['oldPassword']).hexdigest()
    newPassword = hashlib.sha224(request.form['newPassword']).hexdigest()
    if (token in loggedInUsers.keys()):
        dbRet = database_helper.getUser(loggedInUsers[token])
        if (dbRet == []):
            return jsonify(success = False, message = "User does not exist")
        else:
            email = loggedInUsers[token]
            dbRet = database_helper.changePassword(email, oldPassword, newPassword)
            if (dbRet):
                return jsonify(success = True, message = "Password changed")
            else:
                return jsonify(success = False, message = "Incorrect password")
    else:
        return jsonify(success = False, message = "Not logged in")                     
Ejemplo n.º 5
0
def signIn():
    email = request.form['email']
    password = request.form['password']
    user = database_helper.getUser(email)
    
    success = True
    message = "User is logged in"
    
    if (user == []):
        success = False
        message = "User does not exist"
        return jsonify(message = message, success = success)
    else:
        if (user[0][1] == hashlib.sha224(password).hexdigest()):
            token = binascii.b2a_hex(os.urandom(15))
            loggedInUsers[token] = email
            return jsonify(message = message, success = success, token = token)
        else:
            success = False
            message = "Incorrect password"
            return jsonify(message = message, success = success)
Ejemplo n.º 6
0
			return json.dumps({'success' : True, 'message' : 'you signed out'})
	except Exception, e:
		return json.dumps({'success' : False, 'message' : 'you are not signed in'})
		

@app.route('/changepassword', methods=["POST"])
def changePassword():
	#Changes a users password
	token = request.form['token']
	oldPass = request.form['oldpassword']
	newPass = request.form['newpassword']
	try:
		email = loggedInUsers[token]
	except Exception, e:
		return json.dumps({'success' : False, 'message' : 'you are not signed in'})
	info = database_helper.getUser(email)
	if verifyPass(oldPass, info[1]):
		hashPass = hashPassword(newPass)
		database_helper.changePassword(email, hashPass)
		return json.dumps({'success' : True, 'message' : 'password changed'})
	else:
		return json.dumps({'success' : False, 'message' : 'wrong password'})
		

@app.route('/getuserdata')
def getUserDataByToken():
	#Retrieves userdata from token
	token = request.args.get('token')
	try:
		email = loggedInUsers[token]
	except Exception, e: