예제 #1
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('listing'))
    form = RegistrationForm()
    if form.validate_on_submit():
        existing_email = users.find_one({'email': form.email.data})
        # Create new user only if email is not already in use
        if existing_email is None:
            hashed_password = bcrypt.generate_password_hash(
                                form.password.data
                                ).decode('utf-8')
            users.insert_one({
                "username": form.username.data,
                "email": form.email.data,
                "password": hashed_password,
            })
            # Log in once user is created in db
            user = users.find_one({'email': form.email.data})
            login_user(User(user), remember=False)
            flash(f'Account created for {form.username.data}.', 'success')
            return redirect(url_for('listing'))
        else:
            flash(f'Something went wrong with the information provided.',
                   'danger')

    return render_template(
                            'pages/registration.html',
                            title="Registration",
                            form=form)
예제 #2
0
def login():
    # Redirect to listing page if user is logged in
    if current_user.is_authenticated:
        return redirect(url_for('listing'))
    form = LoginForm()
    if form.validate_on_submit():
        user = users.find_one({'email': form.email.data})
        # If user exists and password matches password in db,
        # log in and create a user session
        if user and bcrypt.check_password_hash(
                        user['password'],
                        form.password.data.encode('utf-8')):
            username = user['username']
            # Save session, even after browser is closed
            login_user(User(user), remember=form.remember.data)

            # Checks where to redirect the user after login
            next_page = request.args.get('next')
            flash(f'Welcome to squirrel, {username}.', 'success')

            # If unauthorized page has been accessed before being logged in,
            # redirect to it after login if it is safe
            if next_page and is_safe_url(next_page, socket.gethostname()):
                return redirect(next_page)

            # If not, redirect to the listing page
            else:
                return redirect(url_for('listing'))
        else:
            flash(
                'Login unsucessful, please check email and password.',
                'danger')

    return render_template('pages/login.html', title="Login", form=form)
예제 #3
0
 def user_loader(username):
     try:
         json = users.find_one({'username': username})
         user = User(json)
         return user
     except:
         return
예제 #4
0
def start(bot, update, user_data):
    user_data['wish_list'] = []
    id = update.message.chat_id
    user = users.find_one({'id': id})
    if user:
        user_data.update(user)
    update.message.reply_text("Hi! i am digidooniBot", reply_markup=markup)
    return REQ
예제 #5
0
파일: login.py 프로젝트: kafura-kafiri/herb
 def user_loader(username):
     try:
         json = users.find_one({'username': username})
         user = User(json)
         if isinstance(user.carts, dict):
             user.carts = pqdict(user.carts, key=lambda x: x[2])
         return user
     except:
         return
예제 #6
0
파일: login.py 프로젝트: kafura-kafiri/herb
 def login():
     if request.method == 'GET':
         return render_template('user/login.html')
         return '''
                <form action='login' method='POST'>
                 <input type='text' name='username' id='username' placeholder='username'></input>
                 <input type='password' name='password' id='password' placeholder='password'></input>
                 <input type='submit' name='submit'></input>
                </form>
                '''
     error = ''
     json = None
     if 'username' in request.form:
         json = users.find_one({'username': request.form['username']})
         if not json:
             json = users.find_one({'email': request.form['username']})
     elif 'email' in request.form:
         json = users.find_one({'email': request.form['email']})
         if not json:
             json = users.find_one({'username': request.form['email']})
     else:
         error = 'id not found'
     if not json:
         error = 'not found'
     elif check_password_hash(json['password'], request.form['password']):
         user = User(json)
         # user.carts = pqdict(user.carts, key=lambda x: x[2])
         login_user(user)
     else:
         error = 'password mismatch'
     if 'redirect' in request.form:
         _redirect = request.values['redirect']
         _parse = urlparse(_redirect)
         url = _parse[2]
         params = urllib.parse.parse_qs(_parse[4])
         if error:
             params['msg'] = error
         elif 'msg' in params:
             del params['msg']
         _redirect = url + '?' + '&'.join([key + '=' + value for key, value in params.items()])
         return redirect(_redirect)
     elif not error:
         return redirect(url_for('protected'))
     abort(403, error)
예제 #7
0
 def request_loader(request):
     username = request.form.get('username')
     try:
         json = users.find_one({'username': username})
         user = User(json)
         user.is_authenticated = sha256(request.form['password'].encode()
                                        ).hexdigest() == user['password']
         return user
     except:
         return
예제 #8
0
파일: login.py 프로젝트: kafura-kafiri/herb
 def request_loader(request):
     username = request.form.get('username')
     try:
         json = users.find_one({'username': username})
         user = User(json)
         user.is_authenticated = check_password_hash(user.password, request.form['password'])
         if isinstance(user.carts, dict):
             user.carts = pqdict(user.carts, key=lambda x: x[2])
         return user
     except:
         return
예제 #9
0
def answer_motivation(bot, update, user_data):
    query = update.callback_query
    action = query.data
    user_id = query.message.chat_id
    user = users.find_one({'_id': user_id})
    user['motivation'] = action
    bot.edit_message_text(
        text='your answer was: ' + action,
        chat_id=query.message.chat_id,
        message_id=query.message.message_id,
    )
    return user_data['redirect'](bot, update, user_data)
예제 #10
0
def ask_motivation(bot, update, user_data):
    user_id = update.message.chat_id
    user = users.find_one({'_id': user_id})
    if 'motivation' in user:
        return user_data['redirect'](bot, update, user_data)
    user_data['answer'] = answer_motivation
    keyboard = [[
        telegram.InlineKeyboardButton('local', callback_data=0),
        telegram.InlineKeyboardButton('town', callback_data=1),
        telegram.InlineKeyboardButton('city', callback_data=2),
    ]]
    reply_markup = telegram.InlineKeyboardMarkup(keyboard)
    update.message.reply_text('how far would you go for buying cheaper pr:',
                              reply_markup=reply_markup)
    return PRETTY_RANDOM_QUESTIONS
예제 #11
0
	def create(self,name,email,passwrd):
		user=users.find_one({"email":email})
		
		if user!=None:
			return "This Email Already Exists."
		else:
			temp_user={}
			temp_user['email']=email
			temp_user['userid']=self.gen_id(name, email)
			temp_user['password']=base64.b64encode(passwrd)
			temp_user['key']=self.gen_api_key(temp_user['userid']+passwrd)
			print temp_user
			try:
				ins_id = users.insert(temp_user)
				return "Success ID: "+temp_user['userid']+" API_KEY: " + temp_user['key']
			except:
				return "Error : User Not Created"
예제 #12
0
    def login():
        if request.method == 'GET':
            _redirect, _redirect_url, ctx = '', '', {}
            if 'redirect' in request.values:
                _redirect = request.values['redirect']
                ctx['redirect'] = _redirect
                _redirect = "<input type='hidden' name='redirect' id='redirect' value='{}'></input>".format(
                    _redirect)
            elif 'prev_url' in request.values or 'next' in request.values:
                try:
                    _redirect_url = request.values['prev_url']
                except:
                    _redirect_url = request.values['next']
                ctx['prev_url'] = _redirect_url
                _redirect_url = "<input type='hidden' name='prev_url' id='prev_url' value='{}'></input>".format(
                    _redirect_url)

            return render_template('user/login.html', **ctx)
            '''
                   <form action='login' method='POST'>
                    <input type='text' name='username' id='username' placeholder='username'></input>
                    <input type='password' name='password' id='password' placeholder='password'></input>
                    <input type='submit' name='submit'></input>
                    {redirect}{redirect_url}
                   </form>
                   '''.format(redirect=_redirect, redirect_url=_redirect_url)
        username = request.form['username']
        json = users.find_one({'username': username})
        if sha256(request.form['password'].encode()).hexdigest(
        ) == json['password']:
            user = User(json)
            login_user(user)
            if 'redirect' in request.form:
                _redirect = request.form['redirect']
                return redirect(url_for(_redirect))
            elif 'prev_url' in request.form:
                return redirect(request.form['prev_url'])
            else:
                return redirect(url_for('protected'))

        return 'Bad login'
예제 #13
0
	def get_api_key(self, userid):
		log_user = users.find_one({'userid':userid})
		if log_user==None:
			return None
		return str(log_user['key'])
예제 #14
0
 def auto_login():
     admin = users.find_one({'username': '******'})
     login_user(User(admin))
     return redirect(url_for('protected'))
예제 #15
0
파일: login.py 프로젝트: jumboduck/squirrel
def load_user(user_id):
    user = users.find_one({'_id': ObjectId(user_id)})
    return User(user)