Ejemplo n.º 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)
Ejemplo n.º 2
0
def main():

    try:
        form = CGIgetForm()
        user = CGIlogin(form)
        if user:
            if form.has_key("cancel"):
                print ContactsPage()
            elif form.has_key("delete"):
                if form.has_key("username"):
                    c = Contact(form["username"])
                    c.Delete()
                    message = "Contact deleted"
                else:
                    message = "Contact not specified"
                print ContactsPage(message)
            elif form.has_key("firstname") and form.has_key("lastname"):
                name = "%s %s" % (form["firstname"], form["lastname"])
                if name == form["username"]:
                    c = Contact(name)
                else:
                    c = Contact()
                    c.user = name
                    c.name = name
                    c.firstname = form["firstname"]
                    c.lastname = form["lastname"]
                    oldContact = Contact(form["username"])
                    c.phone = oldContact.phone
                    c.email = oldContact.email
                    oldContact.Delete()
                message = "Contact details successfully updated"
                if form.has_key("email"):
                    if IsEmail(form["email"]):
                        c.email = form["email"]
                    else:
                        message = "Invalid email address"
                else:
                    c.email = ""
                if form.has_key("phone"):
                    c.phone = form["phone"]
                else:
                    c.phone = ""
                c.Store()
                print ContactsPage(message)
            else:
                print ContactsPage("Name not fully specified")
        else:
            print LoginPage(script="ModifyContact.py", form=form)
    except CalendarError, errorText:
        print ErrorPage(errorText)