Example #1
0
def login():
    """
    Log in the user to the system using Google oauth login.
    Note: What gets done here depends on what phase of the login process we are in.
    If this is the INITIAL PHASE, then send the user to the Google login.
    If we are COMING BACK from a Google login, use the code to get the email and display name set up for the user.
    :return: An appropriate redirect (depending on what step of the login process this is.
    """
    domain = parser["learningmachine"]["domain"]
    secrets_file = "{}/{}".format(dir_path, "client_secret.json")
    scope = "https://www.googleapis.com/auth/userinfo.email"
    redirect_uri = "http://{}/login".format(domain)
    login_handler = LoginHandler(secrets_file, scope, redirect_uri)

    if "code" in request.args:
        login_handler.setup_user_info(request.args["code"])
        session["email"] = login_handler.email
        session["display_name"] = login_handler.display_name

        if not model.user_exists(login_handler.email):
            msg = "Adding user: {} with ID of {} to the database."\
                .format(login_handler.email, login_handler.display_name)
            model.add_user(login_handler.email, login_handler.display_name)

        msg = "Sending user: {} to main page".format(login_handler.email)
        app.logger.info(msg)
        return redirect("/static/main.html")

    else:
        msg = "No login code yet.  Letting Google handle the login process at: {}"\
                .format(login_handler.auth_url)
        app.logger.info(msg)
        return redirect(login_handler.auth_url)
Example #2
0
def make_user(username, password):
    existing = model.get_user(username)
    if existing:
        print "Updating existing user"
        model.update_user(username, password)
    else:
        print "Creating new user"
        model.add_user(username, password)
def process_signup():
    email = request.form['username']
    password = request.form['password']
    age = request.form['age']
    gender = request.form['gender']
    occupation = request.form['occupation']
    zipcode = request.form['zipcode']
    model.add_user(email, password, age, gender, occupation, zipcode)
    return redirect("/")
Example #4
0
 def POST(self):
     i = web.input()
     user_form = self.form()
     if not user_form.validates():
         return render.admin(model.get_all_users(),user_form)
     if 'uid' in i:
         model.del_user(i.cin, i.uid)
     elif 'username' in i:
         uname, pwd, email = i.username.strip().lower(), i.password.strip(), i.email.strip()
         pwd = bcrypt.hashpw(pwd, bcrypt.gensalt(BCRYPT_WLOAD))
         model.add_user(i.cin, uname,pwd, email)
     return render.admin(model.get_all_users(), user_form)
Example #5
0
File: app.py Project: smialy/ssrp
def registration():
    if request.method == 'POST':
        login = request.form['login']
        salt = request.form['salt']
        v = request.form['v']
        
        if model.has_user(login):
            return jsonify(dict(error=True, message="User exits"))
        
        model.add_user(login, salt, v)
        return jsonify(dict(error=False))
    else:
        return render_template('registration.html')
Example #6
0
 def POST(self):
     i = web.input()
     form = self.form()
     if not form.validates() or i.username in [u.username for u in model.get_all_users()]:
         return render.register(form,model.get_all_users())
     else:
         cin, uname, pwd, email = i.cin, i.username.strip().lower(), i.password.strip(), i.email.strip()
         #register parsing here
         pwd = bcrypt.hashpw(pwd, bcrypt.gensalt(BCRYPT_WLOAD))
         model.add_user(cin, uname,pwd, email)
         session.logged_in = True
         session.username = uname
         session.cin = cin
         raise web.seeother('/')
Example #7
0
def command_register(update):
    parts = update.message.text.split()

    if not len(parts) == 3:
        raise InvalidCommand('Usage: /register username password')

    username, password = parts[1:]
    try:
        BeerBot(username, password).get_weblaunch_start()
    except LoginException:
        return {'text': 'Invalid username or password.'}

    model.add_user(update.message.chat_id, username, password)
    return {'text': 'Created user.'}
Example #8
0
    def POST(self):
        form=self.registerForm
        if not form.validates():
            return render.register(self.registerForm, "The form did not validate.")
        else:
            username=form.d.username
            password=form.d.password
            email=form.d.email
            users=db.select('users')
            for user in users:
                if username==user.username:
                    return render.register(self.registerForm, "Username already taken")

            hashedPassword=bcrypt.hashpw(password, bcrypt.gensalt())
            model.add_user(username, hashedPassword, email)
            return render.register(self.blankForm, "Success!")
Example #9
0
def shuotest1():  
    results = ''
    results += '<p>[TEST] ADD a user, list the number of users, and all users name and email</p>'
    name = 'Lucy'
    pwd = 'llll'
    email = name +'@brandeis.edu' 
    
    #test
    #model.add_user(name,pwd,email)
    
    #for count in  model.add_user('Alex','1','*****@*****.**'):
        #results += '<p>add a new user</p><br/><p>current total number of users: ' + str(count['total_user']) + '</p><hr/>'

    #results +='<p>TOTAL USERS: '+str(model.add_user('Kiki','000','*****@*****.**'))+'</p>'
    #test
    for total in DB().query('SELECT COUNT(*) AS total_user FROM users'):
        results +='<p>total users:'+str(total['total_user'])+'</p>'
        
    #test, add a user
    results +='<p>[TEST] Add a user:'******'</p>'
    
    
    for row in model.get_users():
        results += '<p>'+row['user']+' '+ row ['email']+'</p>'
    
    return results
Example #10
0
 def POST(self):
     if not check_priv_lvl(2):
         raise web.notfound("You don't have the right privilege level to access this")
     i = web.input(cin=None)
     user_form = self.form()
     client_form = self.cin_form()
     if 'uid' in i:
         logger.info("Deleting user")
         model.del_user(i.cin, i.uid)
         logger.debug('User Deleted: %d',i.uid)
     elif 'new_client' in i:
         if client_form.validates():
             logger.info("Adding new client")
             model.add_client(i.new_client, i.client_name)
             logger.debug('Client Added: %d|%s',i.new_client, i.client_name)
     elif 'username' in i:
         logger.info("Adding user")
         if not user_form.validates():
             return render.admin(model.get_all_users() if session.cin==0 else model.get_user_by_cin(session.cin), user_form, client_form)
         uname, pwd, email = i.username.strip().lower(), i.password.strip(), i.email.strip()
         pwd = bcrypt.hashpw(pwd, bcrypt.gensalt(BCRYPT_WLOAD))
         cin = i.cin if i.cin else session.cin
         ret = model.add_user(cin, uname,pwd, email, i.privilege)
         #Checks if CIN exists and if CIN/Username combination exists
         if ret == 0:
             raise web.notfound("No client exists with this CIN")
         elif ret == -1:
             raise web.notfound("Username exists with identical CIN")
         logger.debug('User added %s', uname)
     raise web.seeother('/admin')
Example #11
0
def new_user():
    email = request.form.get("email")
    pwd = request.form.get("password")
    verify_pwd = request.form.get("password_verify")
    age = request.form.get("age")
    zipcode = request.form.get("zipcode")

    if (pwd == verify_pwd) and (email and pwd and age and zipcode):
        if model.is_user(email):
            flash("You're already registered. Please sign in.")
            return redirect(url_for("signin"))
        else:
            model.add_user(email, pwd, age, zipcode)
            flash("Thanks for registering! Please sign in.","success")
            return redirect(url_for("signin"))
    elif pwd != verify_pwd:
        flash("Passwords must match.","error")
        return redirect(url_for("register"))
    else:
        flash("All fields are required.","error")
        return redirect(url_for("register"))
Example #12
0
def add_user():
    #SHUO: should get name, pwd, and emial from the registration page. 
    #name = 'Jeanne'
    #pwd = '222'
    #email = name +'@brandeis.edu' 
    name = bottle.request.forms.get('user')
    pwd = bottle.request.forms.get('password')
    email = bottle.request.forms.get('email')
    
    results = ''
    results +=model.add_user(name, pwd, email)
    return results
Example #13
0
def register_user():
    """Register or sign up user"""

    #post requests mean they've submitted form on register.html
    if request.method == 'POST':
        user_email = request.form.get('email')
        user_password = request.form.get('password')
        user_age = int(request.form.get('age'))
        user_zipcode = request.form.get('zipcode')
        result = get_user_by_email(user_email) #querying DB for username

        if result:
            ##SHOW ALERT, "username exists"
            flash('That %s already exists. Please login or use a different email' % user_email)
            return redirect('/register')
        else:
            add_user(user_email, user_password, user_age, user_zipcode)
            flash('%s has been successfully registered and logged in.' % user_email)
            session['user_id'] = result.user_id
            return redirect('/')
    else:
        # coming from link on homepage.html
        return render_template("register.html")
Example #14
0
def register():
    """Register new user and login."""
    
    # @todo validate form data in javascript
    user_name = request.form.get('register_user_name')
    password = request.form.get('register_password')
    first_name = request.form.get('register_first_name')
    last_name = request.form.get('register_last_name')
    email = request.form.get('register_email')
    business_name = request.form.get('register_business_name')
    # store password as hash
    password = bcrypt.generate_password_hash(password)
    
    # ensure username is unique (case insensitive)
    user = User.query.filter(User.user_name.ilike(user_name)).first()

    if user:
        flash('The username {} is already in use. Please select another username.'.format(user_name))
        return redirect('/')

    else:
        new_user = add_user(user_name=user_name, password=password, 
                            first_name=first_name, last_name=last_name, email=email)
        login_user(new_user)
        # @todo needs to be broken out for future implementation of multiple users
        # @todo needs to check for duplicate businesses
        if business_name:
            # if a business name was entered, create that business and associate with this user
            new_business = add_business(business_name=business_name,
                                business_street='',
                                business_city='',
                                business_state='',
                                business_zip='',
                                business_phone='',
                                url='',
                                license='')
            new_user.update_user(business_id=new_business.id)
            return redirect('/business/{}'.format(current_user.business_id))
        else:
            return redirect('/business')
Example #15
0
 def POST(self):
     data = web.data()#POST data
     model.add_user(uuid,name,sex)
     buf = json.dumps({'uid':uid})
     web.header('Content-Type','application/json')
     return buf