Esempio n. 1
0
    def user_delete(username):
        title = "Delete user"

        if not ldap_user_exists(username=username):
            abort(404)

        form = Form(request.form)

        if form.validate_on_submit():
            try:
                user = ldap_get_user(username=username)
                ldap_delete_entry(user['distinguishedName'])
                flash("User successfuly deleted.", "success")
                return redirect(url_for('core_index'))
            except ldap.LDAPError as e:
                error = e.message['info'].split(":", 2)[-1].strip()
                error = str(error[0].upper() + error[1:])
                flash(error, "error")
        elif form.errors:
            flash("Some fields failed validation.", "error")

        return render_template("pages/user_delete.html",
                               title=title,
                               action="Delete user",
                               form=form,
                               username=username,
                               parent=url_for('user_overview',
                                              username=username))
def edit_campaign(campaign_id):
    response = sg.client.campaigns._(campaign_id).get()
    campaign = json.loads(response.response_body)
    list_name = None
    try:
        list_id = campaign['list_ids'][0]
        list_response = sg.client.contactdb.lists._(list_id).get()
        list_details = json.loads(list_response.response_body)
        list_name = list_details['name']
    except IndexError:
        list_id = 'null'
        list_name = "No list selected"

    schedule = Form()

    if schedule.validate_on_submit():
        date_unicode = request.form['datetime']
        schedule = datetime.strptime(date_unicode, '%Y-%m-%dT%H:%M')

        send_at = int(mktime(schedule.timetuple()))
        print(send_at)
        request_body = {"send_at": send_at}
        if campaign['s tatus'] == 'Draft':
            sg.client.campaigns._(campaign_id).schedules.post(
                request_body=request_body)
        elif campaign['status'] == 'Scheduled':
            sg.client.campaigns._(campaign_id).schedules.patch(
                request_body=request_body)
        flash("The campaign has been scheduled.")

    return render_template('campaign_page.html',
                           campaign=campaign,
                           campaign_id=campaign_id,
                           list_name=list_name,
                           schedule=schedule)
Esempio n. 3
0
    def user_delete(username):
        title = "Delete user"

        if not ldap_user_exists(username=username):
            abort(404)

        form = Form(request.form)

        if form.validate_on_submit():
            try:
                user = ldap_get_user(username=username)
                ldap_delete_entry(user['distinguishedName'])
                flash("User successfuly deleted.", "success")
                return redirect(url_for('core_index'))
            except ldap.LDAPError as e:
                error = e.message['info'].split(":", 2)[-1].strip()
                error = str(error[0].upper() + error[1:])
                flash(error, "error")
        elif form.errors:
                flash("Some fields failed validation.", "error")

        return render_template("pages/user_delete.html", title=title,
                               action="Delete user", form=form,
                               username=username,
                               parent=url_for('user_overview',
                                              username=username))
Esempio n. 4
0
def login():
    if request.method == 'GET':
        form = Form()
        return render_template('login.html', form=form)
    elif request.method == 'POST':
        form = admin.login()
        if form.validate_on_submit():
            if form.vcode.data != session['verification_code']:
                flash({u'invalid_v_code': ['verification code not correct']},
                      'error')
                return redirect('login')
        else:
            flash(form.errors, 'error')
            return redirect('login')

        secure_password = hashlib.sha1(form.email.data +
                                       form.password.data).hexdigest()
        secure_password_md5 = hashlib.md5(secure_password).hexdigest()
        user = Admin.query.filter(Admin.email == form.email.data).\
                           filter(Admin.password == secure_password_md5).first()
        if user is None:
            flash({u'user_not_exists': [u'user not exists']}, 'error')
            return redirect('login')

        login_user(user, remember=False)
        return redirect(request.args.get('next') or url_for('index'))
Esempio n. 5
0
 def validate_on_submit(self):
     if not Form.validate_on_submit(self):
         return False
     usere = models.User.query.filter_by(email=self.email.data).first()
     if usere == None:
         self.email.errors.append('No such email exists in our database.')
         return False
     return True
Esempio n. 6
0
    def validate_on_submit(self):
        if not Form.validate_on_submit(self):
            return False

        isError = False
        user = models.User.query.filter_by(username=self.username.data).first()
        if user:
            self.username.errors.append("This username is already registered")
            isError = True
        return not isError
def delete(shelter_id):
    shelter = Shelter.query.filter_by(id=shelter_id).one()
    form = Form()

    if form.validate_on_submit():
        db.session.delete(shelter)
        db.session.commit()
        flash(shelter.name + " was deleted from the database.")
        return redirect(url_for("shelters.list_all"))

    return render_template("shelters/delete.jinja2", form=form, shelter=shelter)
Esempio n. 8
0
def delete(puppy_id):
    puppy = Puppy.query.filter_by(id=puppy_id).one()
    # we can use a generic form, since there are no fields
    form = Form()

    if form.validate_on_submit():
        db.session.delete(puppy)
        db.session.commit()
        flash(puppy.name + " was put to sleep.")
        return redirect(url_for("puppies.list_all"))

    return render_template("puppies/delete.jinja2", form=form, puppy=puppy)
def delete(adopter_id):
    adopter = Adopter.query.filter_by(id=adopter_id).one()
    # we can use a generic form, since there are no fields
    form = Form()

    if form.validate_on_submit():
        db.session.delete(adopter)
        db.session.commit()
        flash(adopter.name + " was deleted from the database.")
        return redirect(url_for("adopters.list_all"))

    return render_template("adopters/delete.jinja2", form=form, adopter=adopter)
def delete(puppy_id):
    puppy = Puppy.query.filter_by(id=puppy_id).one()
    # we can use a generic form, since there are no fields
    form = Form()

    if form.validate_on_submit():
        db.session.delete(puppy)
        db.session.commit()
        flash(puppy.name + " was put to sleep.")
        return redirect(url_for("puppies.list_all"))

    return render_template("puppies/delete.jinja2", form=form, puppy=puppy)
Esempio n. 11
0
def logout():
    form = Form()
    if form.validate_on_submit():
        logout_user()
        if 'redirect_to' in session:
            redirect_to = session['redirect_to']
            session.pop('redirect_to', None)
        flash(gettext('Signed out successfully.'))
    else:
        flash(gettext('Invalid Action'), 'error')

    return redirect(url_for('index'))
def delete(shelter_id):
    shelter = Shelter.query.filter_by(id=shelter_id).one()
    form = Form()

    if form.validate_on_submit():
        db.session.delete(shelter)
        db.session.commit()
        flash(shelter.name + " was deleted from the database.")
        return redirect(url_for("shelters.list_all"))

    return render_template("shelters/delete.jinja2",
                           form=form,
                           shelter=shelter)
Esempio n. 13
0
 def validate_on_submit(self):
     if not Form.validate_on_submit(self):
         return False
     user_to_check = models.User.query.filter_by(
         username=self.username.data).first()
     if not user_to_check:
         self.username.errors.append("No user with this username exists")
         return False
     if (user_to_check
             and not user_to_check.check_password(self.password.data)):
         self.password.errors.append("Authentication failed")
         return False
     return True
Esempio n. 14
0
def delete(adopter_id):
    adopter = Adopter.query.filter_by(id=adopter_id).one()
    # we can use a generic form, since there are no fields
    form = Form()

    if form.validate_on_submit():
        db.session.delete(adopter)
        db.session.commit()
        flash(adopter.name + " was deleted from the database.")
        return redirect(url_for("adopters.list_all"))

    return render_template("adopters/delete.jinja2",
                           form=form,
                           adopter=adopter)
Esempio n. 15
0
 def validate_on_submit(self):
     if not Form.validate_on_submit(self):
         return False
     usere = models.User.query.filter_by(email=self.email.data).first()
     if usere != None:
         self.email.errors.append(
             'This email is already in use. Please choose another one.')
         return False
     usern = models.User.query.filter_by(
         nickname=self.nickname.data).first()
     if usern != None:
         self.nickname.errors.append(
             'This nickname is already in use. Please choose another one.')
         return False
     useru = models.User.query.filter_by(
         username=self.username.data).first()
     if useru != None:
         self.username.errors.append(
             'This username is already in use. Please choose another one.')
         return False
     return True
Esempio n. 16
0
    def group_delmember(groupname, member):
        title = "Remove group member"

        group = ldap_get_group(groupname)
        if not group or 'member' not in group:
            abort(404)

        member = ldap_get_entry_simple({'sAMAccountName': member})
        if not member:
            abort(404)

        if not member['distinguishedName'] in group['member']:
            abort(404)

        form = Form(request.form)

        if form.validate_on_submit():
            try:
                members = group['member']
                members.remove(member['distinguishedName'])
                ldap_update_attribute(group['distinguishedName'], "member",
                                      members)
                flash("Member removed.", "success")
                return redirect(url_for('group_overview', groupname=groupname))
            except ldap.LDAPError as e:
                error = e.message['info'].split(":", 2)[-1].strip()
                error = str(error[0].upper() + error[1:])
                flash(error, "error")
        elif form.errors:
            flash("Some fields failed validation.", "error")

        return render_template("pages/group_delmember.html",
                               title=title,
                               action="Remove group member",
                               form=form,
                               member=member['sAMAccountName'],
                               group=group['sAMAccountName'],
                               parent=url_for('group_overview',
                                              groupname=groupname))
Esempio n. 17
0
    def group_delmember(groupname, member):
        title = "Remove group member"

        group = ldap_get_group(groupname)
        if not group or 'member' not in group:
            abort(404)

        member = ldap_get_entry_simple({'sAMAccountName': member})
        if not member:
            abort(404)

        if not member['distinguishedName'] in group['member']:
            abort(404)

        form = Form(request.form)

        if form.validate_on_submit():
            try:
                members = group['member']
                members.remove(member['distinguishedName'])
                ldap_update_attribute(group['distinguishedName'],
                                      "member", members)
                flash("Member removed.", "success")
                return redirect(url_for('group_overview', groupname=groupname))
            except ldap.LDAPError as e:
                error = e.message['info'].split(":", 2)[-1].strip()
                error = str(error[0].upper() + error[1:])
                flash(error, "error")
        elif form.errors:
                flash("Some fields failed validation.", "error")

        return render_template("pages/group_delmember.html", title=title,
                               action="Remove group member", form=form,
                               member=member['sAMAccountName'],
                               group=group['sAMAccountName'],
                               parent=url_for('group_overview',
                                              groupname=groupname))
Esempio n. 18
0
    def validate_on_submit(self):
        if not Form.validate_on_submit(self):
            return False

        return True