Exemplo n.º 1
0
def resend_email_confirmation():
    user = login.current_user
    if not user.is_verified:
        s = get_serializer()
        email = user.email
        form_hash = s.dumps([email, str_generator()])
        link = url_for('.create_account_after_confirmation_view',
                       hash=form_hash,
                       _external=True)
        data = {"email": email}
        send_email_confirmation(data, link)
        flash('Confirmation email has been sent again.', 'info')
    else:
        flash('Your email has already been confirmed.', 'info')
    return redirect(url_for('events.index_view'))
Exemplo n.º 2
0
def resend_email_confirmation():
    user = login.current_user
    if not user.is_verified:
        s = get_serializer()
        email = user.email
        form_hash = s.dumps([email, str_generator()])
        link = url_for('.create_account_after_confirmation_view', hash=form_hash, _external=True)
        data = {
            "email": email
        }
        send_email_confirmation(data, link)
        flash('Confirmation email has been sent again.', 'info')
    else:
        flash('Your email has already been confirmed.', 'info')
    return redirect(url_for('events.index_view'))
Exemplo n.º 3
0
def register_view():
    if request.method == 'GET':
        return render_template('gentelella/users/login/register.html')
    if request.method == 'POST':
        logging.info("Registration under process")
        s = get_serializer()
        data = [request.form['email'], request.form['password']]
        user = DataManager.create_user(data)
        form_hash = s.dumps([request.form['email'], str_generator()])
        link = url_for('.create_account_after_confirmation_view', hash=form_hash, _external=True)
        send_email_confirmation(request.form, link)
        login.login_user(user)
        record_user_login_logout('user_login', user)
        logging.info('logged successfully')
        user_logged_in(user)
        return redirect(intended_url())
Exemplo n.º 4
0
def register_view():
    if request.method == 'GET':
        return render_template('gentelella/admin/login/register.html')
    if request.method == 'POST':
        logging.info("Registration under process")
        s = get_serializer()
        data = [request.form['email'], request.form['password']]
        user = DataManager.create_user(data)
        form_hash = s.dumps([request.form['email'], str_generator()])
        link = url_for('.create_account_after_confirmation_view',
                       hash=form_hash,
                       _external=True)
        send_email_confirmation(request.form, link)
        login.login_user(user)
        record_user_login_logout('user_login', user)
        logging.info('logged successfully')
        user_logged_in(user)
        return redirect(intended_url())
Exemplo n.º 5
0
    def update_user(form, user_id, contacts_only_update=False):

        user = User.query.filter_by(id=user_id).first()
        user_detail = UserDetail.query.filter_by(user_id=user_id).first()

        if user.email != form['email']:
            record_activity('update_user_email',
                            user_id=user.id, old=user.email, new=form['email'])
        if user.email != form['email']:
            user.is_verified = False
            serializer = Helper.get_serializer()
            data = [form['email']]
            form_hash = serializer.dumps(data)
            link = url_for('admin.create_account_after_confirmation_view', hash=form_hash, _external=True)
            Helper.send_email_when_changes_email(user.email, form['email'])
            Helper.send_notif_when_changes_email(user, user.email, form['email'])
            Helper.send_email_confirmation(form, link)
            user.email = form['email']

        user_detail.contact = form['contact']
        if not contacts_only_update:
            user_detail.firstname = form['firstname']
            user_detail.lastname = form['lastname']

            if form.get('facebook', '').strip() != '':
                user_detail.facebook = 'https://facebook.com/' + form['facebook'].strip()
            else:
                user_detail.facebook = ''

            if form.get('twitter', '').strip() != '':
                user_detail.twitter = 'https://twitter.com/' + form['twitter'].strip()
            else:
                user_detail.twitter = ''

            if form.get('instagram', '').strip() != '':
                user_detail.instagram = 'https://instagram.com/' + form['instagram'].strip()
            else:
                user_detail.instagram = ''

            if form.get('google', '').strip() != '':
                user_detail.google = 'https://plus.google.com/' + form['google'].strip()
            else:
                user_detail.google = ''

            user_detail.details = form['details']
            avatar_img = form.get('avatar-img', None)
            if string_not_empty(avatar_img) and avatar_img:
                user_detail.avatar_uploaded = ""
                user_detail.thumbnail = ""
                user_detail.small = ""
                user_detail.icon = ""
                filename = '{}.png'.format(get_image_file_name())
                filepath = '{}/static/{}'.format(path.realpath('.'),
                                                 avatar_img[len('/serve_static/'):])
                # print "File path 1", filepath
                avatar_img_file = UploadedFile(filepath, filename)
                avatar_img_temp = upload(avatar_img_file, 'users/%d/avatar' % int(user_id))
                user_detail.avatar_uploaded = avatar_img_temp
                image_sizes = DataGetter.get_image_sizes_by_type(type='profile')
                if not image_sizes:
                    image_sizes = ImageSizes(full_width=150,
                                             full_height=150,
                                             icon_width=35,
                                             icon_height=35,
                                             thumbnail_width=50,
                                             thumbnail_height=50,
                                             type='profile')
                save_to_db(image_sizes, "Image Sizes Saved")
                filename = '{}.jpg'.format(get_image_file_name())
                filepath = '{}/static/{}'.format(path.realpath('.'),
                                                 avatar_img[len('/serve_static/'):])
                # print "File path 1", filepath
                avatar_img_file = UploadedFile(filepath, filename)

                temp_img_file = upload_local(avatar_img_file,
                                             'users/{user_id}/temp'.format(user_id=int(user_id)))
                temp_img_file = temp_img_file.replace('/serve_', '')

                basewidth = image_sizes.full_width
                img = Image.open(temp_img_file)
                hsize = image_sizes.full_height
                img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
                img.save(temp_img_file)
                file_name = temp_img_file.rsplit('/', 1)[1]
                large_file = UploadedFile(file_path=temp_img_file, filename=file_name)
                profile_thumbnail_url = upload(
                    large_file,
                    UPLOAD_PATHS['user']['thumbnail'].format(
                        user_id=int(user_id)
                    ))

                basewidth = image_sizes.thumbnail_width
                img = Image.open(temp_img_file)
                hsize = image_sizes.thumbnail_height
                img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
                img.save(temp_img_file)
                file_name = temp_img_file.rsplit('/', 1)[1]
                thumbnail_file = UploadedFile(file_path=temp_img_file, filename=file_name)
                profile_small_url = upload(
                    thumbnail_file,
                    UPLOAD_PATHS['user']['small'].format(
                        user_id=int(user_id)
                    ))

                basewidth = image_sizes.icon_width
                img = Image.open(temp_img_file)
                hsize = image_sizes.icon_height
                img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
                img.save(temp_img_file)
                file_name = temp_img_file.rsplit('/', 1)[1]
                icon_file = UploadedFile(file_path=temp_img_file, filename=file_name)
                profile_icon_url = upload(
                    icon_file,
                    UPLOAD_PATHS['user']['icon'].format(
                        user_id=int(user_id)
                    ))
                shutil.rmtree(path='static/media/' + 'users/{user_id}/temp'.format(user_id=int(user_id)))
                user_detail.thumbnail = profile_thumbnail_url
                user_detail.small = profile_small_url
                user_detail.icon = profile_icon_url
        user, user_detail, save_to_db(user, "User updated")
        record_activity('update_user', user=user)
Exemplo n.º 6
0
    def update_user(form, user_id, contacts_only_update=False):

        user = User.query.filter_by(id=user_id).first()
        user_detail = UserDetail.query.filter_by(user_id=user_id).first()

        if user.email != form['email']:
            record_activity('update_user_email',
                            user_id=user.id, old=user.email, new=form['email'])
        if user.email != form['email']:
            user.is_verified = False
            serializer = Helper.get_serializer()
            data = [form['email']]
            form_hash = serializer.dumps(data)
            link = url_for('admin.create_account_after_confirmation_view', hash=form_hash, _external=True)
            Helper.send_email_when_changes_email(user.email, form['email'])
            Helper.send_notif_when_changes_email(user, user.email, form['email'])
            Helper.send_email_confirmation(form, link)
            user.email = form['email']

        user_detail.contact = form['contact']
        if not contacts_only_update:
            user_detail.firstname = form['firstname']
            user_detail.lastname = form['lastname']

            if form.get('facebook', '').strip() != '':
                user_detail.facebook = 'https://facebook.com/' + form['facebook'].strip()
            else:
                user_detail.facebook = ''

            if form.get('twitter', '').strip() != '':
                user_detail.twitter = 'https://twitter.com/' + form['twitter'].strip()
            else:
                user_detail.twitter = ''

            if form.get('instagram', '').strip() != '':
                user_detail.instagram = 'https://instagram.com/' + form['instagram'].strip()
            else:
                user_detail.instagram = ''

            if form.get('google', '').strip() != '':
                user_detail.google = 'https://plus.google.com/' + form['google'].strip()
            else:
                user_detail.google = ''

            user_detail.details = form['details']
            avatar_img = form.get('avatar-img', None)
            if string_not_empty(avatar_img) and avatar_img:
                user_detail.avatar_uploaded = ""
                user_detail.thumbnail = ""
                user_detail.small = ""
                user_detail.icon = ""
                filename = '{}.png'.format(get_image_file_name())
                filepath = '{}/static/{}'.format(path.realpath('.'),
                                                 avatar_img[len('/serve_static/'):])
                # print "File path 1", filepath
                avatar_img_file = UploadedFile(filepath, filename)
                avatar_img_temp = upload(avatar_img_file, 'users/%d/avatar' % int(user_id))
                user_detail.avatar_uploaded = avatar_img_temp
                image_sizes = DataGetter.get_image_sizes_by_type(type='profile')
                if not image_sizes:
                    image_sizes = ImageSizes(full_width=150,
                                             full_height=150,
                                             icon_width=35,
                                             icon_height=35,
                                             thumbnail_width=50,
                                             thumbnail_height=50,
                                             type='profile')
                save_to_db(image_sizes, "Image Sizes Saved")
                filename = '{}.jpg'.format(get_image_file_name())
                filepath = '{}/static/{}'.format(path.realpath('.'),
                                                 avatar_img[len('/serve_static/'):])
                # print "File path 1", filepath
                avatar_img_file = UploadedFile(filepath, filename)

                temp_img_file = upload_local(avatar_img_file,
                                             'users/{user_id}/temp'.format(user_id=int(user_id)))
                temp_img_file = temp_img_file.replace('/serve_', '')

                basewidth = image_sizes.full_width
                img = Image.open(temp_img_file)
                hsize = image_sizes.full_height
                img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
                img.save(temp_img_file)
                file_name = temp_img_file.rsplit('/', 1)[1]
                large_file = UploadedFile(file_path=temp_img_file, filename=file_name)
                profile_thumbnail_url = upload(
                    large_file,
                    UPLOAD_PATHS['user']['thumbnail'].format(
                        user_id=int(user_id)
                    ))

                basewidth = image_sizes.thumbnail_width
                img = Image.open(temp_img_file)
                hsize = image_sizes.thumbnail_height
                img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
                img.save(temp_img_file)
                file_name = temp_img_file.rsplit('/', 1)[1]
                thumbnail_file = UploadedFile(file_path=temp_img_file, filename=file_name)
                profile_small_url = upload(
                    thumbnail_file,
                    UPLOAD_PATHS['user']['small'].format(
                        user_id=int(user_id)
                    ))

                basewidth = image_sizes.icon_width
                img = Image.open(temp_img_file)
                hsize = image_sizes.icon_height
                img = img.resize((basewidth, hsize), PIL.Image.ANTIALIAS)
                img.save(temp_img_file)
                file_name = temp_img_file.rsplit('/', 1)[1]
                icon_file = UploadedFile(file_path=temp_img_file, filename=file_name)
                profile_icon_url = upload(
                    icon_file,
                    UPLOAD_PATHS['user']['icon'].format(
                        user_id=int(user_id)
                    ))
                shutil.rmtree(path='static/media/' + 'users/{user_id}/temp'.format(user_id=int(user_id)))
                user_detail.thumbnail = profile_thumbnail_url
                user_detail.small = profile_small_url
                user_detail.icon = profile_icon_url
        user, user_detail, save_to_db(user, "User updated")
        record_activity('update_user', user=user)