Exemple #1
0
def userreg():
    blankuser = Users(user_id=0,
                      first_name='',
                      last_name='',
                      email='',
                      password='',
                      is_admin=True)
    if request.method == 'POST':
        user_id = 1
        tu = uimpl.getAllUsers()
        for i in tu:
            user_id += 1
        first_name = request.form['fname']
        lastname = request.form['lname']
        email = request.form['email']
        password = request.form['password']
        cpassword = request.form['cpassword']
        is_admin = True
        if password != cpassword:
            rmsg = 'Password & Confirm Password must be same'
        else:
            newuser = Users(user_id=user_id,
                            first_name=first_name,
                            last_name=lastname,
                            email=email,
                            password=password,
                            is_admin=is_admin)
            uimpl.addUser(newuser)
            rmsg = 'User Added Successfully. You can Login Now :)'
        return render_template('login_main.html', msg=rmsg)
    return render_template('login_main.html', msg='signup get')
Exemple #2
0
def verify_password(username_or_token, password):
    # first try to authenticate by token
    user = Users.verify_auth_token(username_or_token)
    if not user:
        # try to authenticate with username/password
        try:
            user = Users.get(Users.username == username_or_token)
        except:
            user = None
        if not user or not user.verify_password(password):
            return False
    g.user = user
    return True
Exemple #3
0
def update_user():
    password =  request.forms.get('password').strip()
    conpassword = request.forms.get('conpassword').strip()
    email = request.forms.get('email').strip()
    user_details = logged_in_user()
    token =  request.forms.get('form_token').strip()
    user_session = request.environ.get('beaker.session')
    if token == user_session["token"]:
	del user_session["token"]
	if user_details["id"]:
	    if password is not '' and conpassword is not '' and password == conpassword:
		try:
		    my_return = Users.update_password(user_details["id"] , password)
		    if my_return:
			mymail.send_mail( email=user_details['email'], name=user_details['username'])
			return template("registration",success_message = success_message,  username=user_details["username"] ) 
		    else:
			 template("edit_user", my_top =0, error_message  = error_message, email = user_details["email"], username=user_details["username"])
			 
		except MySQLdb.OperationalError , e:
		    return  template("edit_user", my_top =0, error_message  = error_message, email = user_details["email"], username=user_details["username"])
	    else:
		redirect("/user/edit")
	else:
	    redirect("/user/edit")
Exemple #4
0
def doRegister(username, password):
    try:
        with db.transaction():
            pass_hash = hashlib.md5(password.encode("utf-8")).hexdigest()
            user = Users(username=username,
                         password=pass_hash,
                         created_at=date.today(),
                         is_active=True,
                         score=0,
                         solved=json.dumps([]))
            user.save()
        return True
    except IntegrityError as ex:
        print(ex)
        db.rollback()
        return False
Exemple #5
0
def activate_account():
    activation_number = request.GET.get('activate')
    try:
	status = Users.activate(activation_number)
	if status: 
	    return template("activation_message", message ="Your account is now activated" )
	else:
	    return template("activation_message", message = error_message )
    except MySQLdb.OperationalError , e:
	return template("activation_message", message = error_message )
Exemple #6
0
def logged_in_user():
    s = request.environ.get('beaker.session')
    try:
	if s["user_id"]:
	    try:
		return Users.find_by_id(s['user_id']) 
	    except MySQLdb.OperationalError, e:
		raise
    except KeyError, e:
	return  None
Exemple #7
0
def reset_member_password():
    email = request.forms.get('email').strip()
    if email:
	try:
            password = Users.reset_password(email)
	    print password
	    if password:
	        mymail.send_mail( email=email, password=password) 
		return template("registration",success_message = "A new password was sent to your box",  username=email ) 
	    else:
		return template("reset_password", message="Email not in our data store")
	except MySQLdb.OperationalError , e:
	     return template("reset_password", message="Email not in our data store")
Exemple #8
0
def doLogin(username, password):
    try:
        with db.transaction():
            pass_hash = hashlib.md5(password.encode('utf-8')).hexdigest()
            user = Users.get(Users.username == username
                             and Users.password == pass_hash)
    except (IntegrityError, Users.DoesNotExist) as ex:
        print(ex)
        db.rollback()
        message = "username/password is wrong."
        return (False, message)
    else:
        if user:
            message = "Login Success!"
            return (True, message)
        else:
            message = "username/password is wrong."
            return (False, message)
Exemple #9
0
def create_user():
    username = request.forms.get('username').strip()
    email       =  request.forms.get('email').strip()
    password =  request.forms.get('password').strip()
    conpassword = request.forms.get('conpassword').strip()
    token =  request.forms.get('form_token').strip()
    activation_code = helper.activation_hash()
    user_session = request.environ.get('beaker.session')
    if token == user_session["token"]:
	del user_session["token"]
	if password == conpassword:
	    try:
	       if Users.create(username, email, activation_code, password):
		    mymail.send_mail(email=email, name=username, activation_code = activation_code)
		    return template("registration", success_message = success_message,username=username)
	       else:
		    return template("user_registration_form", error_message = error_message, cond=1)
	    except MySQLdb.OperationalError ,e:
	        return template("user_registration_form", error_message = error_message,cond=1)
	else:
	     return  template("user_registration_form",error_message = error_message, cond=1)   
Exemple #10
0
def login_submit():
    email = request.forms.get('email').strip()
    password = request.forms.get('password').strip()
    obj_session = request.environ.get('beaker.session')
    token =  request.forms.get('form_token').strip()
    if token == obj_session["token"]:
	del obj_session["token"]
        try:
	    user =  Users.find_user_by_password_and_email(password, email)
	    if user:
	        user_session(user['id'])
	        s = request.environ.get('beaker.session')
	        if  s.has_key('url'):
	            url = s['url']
	            del s['url']	
	            redirect(url)	
		reviews =  Reviews.list_all_reviews()		    
	        return template("layout",my_top=user["username"], token=0, reviews=reviews)
	    else:
		return template("alogin", my_top=1, cond=1,token=token, error_message=error_message)  # template("failedlogin")
        except MySQLdb.OperationalError ,e:
	     return template("alogin", my_top=1, cond=1, token=token,error_message=error_message) # template("failedlogin")
Exemple #11
0
def verify_token(token):
    user = Users.verify_auth_token(token)
    if user:
        g.user = user
        return True
    return False