Ejemplo n.º 1
0
def register(param):
	u = Users()
	
	username = param['username']
	hash = param['hash']
	publc = param['publc']
	
	# create a hash
	m = md5.new(username + publc + _private_key())
	
	# check if this hash is equal to the one transmitted
	if m.hexdigest() == hash:
	
		bool = u.user_query(param)
		if bool:
			#user exists
			dat = {
				'status' : 'Error!',
				'message': 'Username exists. Try another one'
			}
		else:
			reg = u.userRegister(param)
			if reg:
				dat = {
					'status' : 'Success',
					'message': 'Registration successful'
				}
			else:
				dat = {
					'status' : 'Error!',
					'message' : 'Registration failed. Try again later.'
				}
		
	return dat
Ejemplo n.º 2
0
def login(param):
	u = Users()
	
	user = u.user_query(param);
	
	if (user):
		data = {
			'user_id'		: user[0][0],
			'user_email'	: user[0][1],
			'user_pass'		: user[0][2],
			'user_active'	: user[0][3]
		}
	
		# create a hash
		m = md5.new(data['user_pass'] + param['publc'] + _private_key())
	
		# check if this hash is equal to the one transmitted
		if m.hexdigest() == param['password']:
			if data['user_active'] == 1:
				result	= 'success'
				message	= data['user_id']
			else:
				result = 'fail'
				message = 'User not activated.'
		else:
			result = 'fail'
			message = 'Authentication failed.'
	else:
		result = 'fail'
		message = 'Authentication failed.'
			
	obj = {
			'result'	: result,
			'message'	: message
		}
		
	return obj