Exemple #1
0
def main():

    try:
        form = CGIgetForm()
        user = CGIlogin(form)
        if user == "admin" or user in GetEditors():
            message = "Contact added"
            if form.has_key("firstname") and form.has_key("lastname"):
                c = Contact()
                c.firstname = form["firstname"]
                c.lastname = form["lastname"]
                c.user = c.firstname + " " + c.lastname
                c.name = c.user
            else:
                raise CalendarError, "No full name specified"
            if form.has_key("phone"):
                c.phone = form["phone"]
            if form.has_key("email"):
                if IsEmail(form["email"]):
                    c.email = form["email"]
                else:
                    message = "Invalid email address"
            #Set an initial password at random
            c.password = SetPassword()
            c.Store()
            print c.ContactPage(message)
        else:
            print LoginPage("Not authorized for this operation",
                            script="AddContact.py",
                            form=form)
    except CalendarError, errorText:
        print AdminPage(errorText)
Exemple #2
0
def main():

    try:
        form = CGIgetForm()
        user = CGIlogin(form)
        if user:
            if form.has_key("contact"):
                username = form["contact"]
                if username not in GetContacts():
                    raise CalendarError, "Invalid contact"
                c = Contact(username)
                print c.ContactPage()
            else:
                raise CalendarError, "No editor specified"
        else:
            print LoginPage(script="EditContact.py", form=form)
    except CalendarError, errorText:
        print ErrorPage(errorText)