Esempio n. 1
0
def send_invitation_to_project(project, inviting, invited, message):
    h = generic.hash_str(invited.salt + str(project.key))
    kw = {
        "project":
        project,
        "inviting":
        inviting,
        "invited":
        invited,
        "message":
        message,
        "APP_URL":
        generic.APP_URL,
        "accept_link":
        "%s/%s/admin?h=%s" % (generic.APP_URL, project.key.integer_id(), h)
    }
    message = mail.EmailMessage(
        sender=PRETTY_ADMIN_EMAIL,
        to=invited.email,
        subject="%s has invited you to collaborate in the project %s" %
        (inviting.username.capitalize(), project.name),
        body=generic.render_str("emails/invite_to_project.txt", **kw),
        html=generic.render_str("emails/invite_to_project.html", **kw))
    logging.debug(
        "EMAIL: Sending an email with a invitation to a project from user %s to user %s"
        % (inviting.username, invited.username))
    message.send()
    return
Esempio n. 2
0
def send_group_biblio_notification(group, user, bibitems):
    kw = {"group"    : group,
          "user"     : user,
          "bibitems" : bibitems,
          "APP_URL"  : generic.APP_URL}
    message = mail.EmailMessage(sender  = PRETTY_ADMIN_EMAIL,
                                to      = user.email,
                                subject = "Weekly bibliography review for %s" % group.name,
                                body    = generic.render_str("emails/group_biblio_notification.txt", **kw),
                                html    = generic.render_str("emails/group_biblio_notification.html", **kw))
    logging.debug("EMAIL: Sending an email with an event notification to user %s" % user.username)
    message.send()
    return
Esempio n. 3
0
 def post(self):
     action = self.request.get('action')
     have_error = False
     email = self.request.get("email")
     if action == "send_email":
         if (not email) or (not re.match(EMAIL_RE, email)):
             have_error = True
             r_error_message = "Please write a valid email."
         if not have_error:
             user = self.get_user_by_email(email)
             if not user:
                 have_error = True
                 r_error_message = "That's not a registered email."
         if have_error:
             self.redirect("/login?r_error_message=%s" % r_error_message)
         else:
             link = '%s/recover_password?email=%s&k=%s' % (generic.APP_URL, email, generic.hash_str(user.username + user.salt))
             message = mail.EmailMessage(sender = generic.APP_NAME + ' <' + generic.ADMIN_EMAIL + '>',
                                         to = email,
                                         subject = 'Password recovery',
                                         body = generic.render_str('emails/recover_password.txt',  reset_link = link, ADMIN_EMAIL = generic.ADMIN_EMAIL),
                                         html = generic.render_str('emails/recover_password.html', reset_link = link, ADMIN_EMAIL = generic.ADMIN_EMAIL))
             if generic.DEBUG: logging.debug("EMAIL: Sending an email for password recovery. ")
             message.send()
             self.redirect('/login?info=Email sent. To reset your password follow the instructions on the email.')
     elif action == "do_reset":
         password = self.request.get("password")
         p_repeat = self.request.get("p_repeat")
         key = self.request.get("k")
         if not (email and key):
             have_error = True
         if not (password and p_repeat and re.match(PASSWORD_RE, password) and password == p_repeat):
             self.redirect('/recover_password?email=%s&k=%s&error=%s' % (email, key, "Please fill both boxes with the same password. "))
             return
         if not have_error:
             user = self.get_user_by_email(email)
             if not user:
                 have_error = True
             elif not key == generic.hash_str(user.username + user.salt):
                 have_error = True
         if have_error:
             self.error(400)
             error = "Invalid request. "
             self.write(error)
         else:
             salt = generic.make_salt()
             user.salt = salt
             user.password_hash = generic.hash_str(password + salt)
             self.log_and_put(user)
             self.redirect("/login?info=Password successfully changed, you can login now with your new password.")
def send_notifications(notifications_list, user):
    if len(notifications_list) == 0: return
    notifs = classify_notifications(notifications_list)
    message = mail.EmailMessage(sender = PRETTY_ADMIN_EMAIL,
                                to = user.email,
                                subject = "Recent activity in your projects",
                                body = generic.render_str("emails/notification_email.txt", **notifs),
                                html = generic.render_str("emails/notification_email.html", **notifs))
    logging.debug("EMAIL: Sending an email with notifications to user %s" % user.username)
    message.send()
    for n in notifications_list:
        n.sent = True
        logging.debug("DB WRITE: CRON: Changing a notification's 'sent' property to True")
        n.put()
    return
Esempio n. 5
0
def send_invitation_to_group(group, inviting, invited):
    h = generic.hash_str(invited.salt + str(group.key))
    kw = {"group" : group,
          "inviting" : inviting,
          "invited" : invited,
          "APP_URL" : generic.APP_URL,
          "accept_link" : "%s/g/%s/invited?h=%s" % (generic.APP_URL, group.key.integer_id(), h)}
    message = mail.EmailMessage(sender = PRETTY_ADMIN_EMAIL,
                                to = invited.email,
                                subject = "%s has invited you to be a member of the group %s" % (inviting.username.capitalize(), group.name),
                                body = generic.render_str("emails/invite_to_group.txt" , **kw),
                                html = generic.render_str("emails/invite_to_group.html", **kw))
    logging.debug("EMAIL: Sending an email with a invitation to a group from user %s to user %s" % (inviting.username, invited.username))
    message.send()
    return
Esempio n. 6
0
def send_notifications(notifications_list, user):
    if len(notifications_list) == 0: return
    notifs = classify_notifications(notifications_list)
    message = mail.EmailMessage(sender = PRETTY_ADMIN_EMAIL,
                                to = user.email,
                                subject = "Recent activity in your projects",
                                body = generic.render_str("emails/notification_email.txt", **notifs),
                                html = generic.render_str("emails/notification_email.html", **notifs))
    logging.debug("EMAIL: Sending an email with notifications to user %s" % user.username)
    message.send()
    for n in notifications_list:
        n.sent = True
        logging.debug("DB WRITE: CRON: Changing a notification's 'sent' property to True")
        n.put()
    return
def send_invitation_to_project(project, inviting, invited, message):
    h = generic.hash_str(invited.salt + str(project.key))
    kw = {"project" : project,
          "inviting" : inviting,
          "invited" : invited,
          "message" : message,
          "APP_URL" : generic.APP_URL,
          "accept_link" : "%s/%s/admin?h=%s" % (generic.APP_URL, project.key.integer_id(), h)}
    message = mail.EmailMessage(sender = PRETTY_ADMIN_EMAIL,
                                to = invited.email,
                                subject = "%s has invited you to collaborate in the project %s" % (inviting.username.capitalize(), project.name),
                                body = generic.render_str("emails/invite_to_project.txt" , **kw),
                                html = generic.render_str("emails/invite_to_project.html", **kw))
    logging.debug("EMAIL: Sending an email with a invitation to a project from user %s to user %s" % (inviting.username, invited.username))
    message.send()
    return
Esempio n. 8
0
def send_new_calendar_event_notification(user, author, group, event, update):
    kw = {"user"    : user,
          "author"  : author,
          "group"   : group,
          "event"   : event,
          "APP_URL" : generic.APP_URL,
          "update"  : update,
          "subject" : "An event has changed in your group " if update else "New event in your group "}
    kw["subject"] = kw["subject"] + group.name
    message = EmailsToSend(sender  = PRETTY_ADMIN_EMAIL,
                           to      = user.email,
                           subject = kw["subject"],
                           body    = generic.render_str("emails/group_event_notification.txt", **kw),
                           html    = generic.render_str("emails/group_event_notification.html", **kw))
    message.put()
    return
 def html_export(self, projectid, nbid):
     "Generates a printer-friendly version of the notebook."
     user = self.get_login_user()
     project = self.get_project(projectid)
     if not project:
         self.error(404)
         self.render("404.html", info = 'Project with key <em>%s</em> not found' % projectid)
         return
     notebook = self.get_notebook(project, nbid)
     if not notebook:
         self.error(404)
         self.render("404.html", info = 'Notebook with key <em>%s</em> not found' % nbid)
         return
     if not (notebook.is_open_p() or (user and project.user_is_author(user))):
         self.render("project_page_not_visible.html", project = project, user = user)
         return
     d = self.request.get("d")
     if d == "desc":
         notes = NotebookNotes.query(ancestor = notebook.key).order(-NotebookNotes.date).fetch()
     else:
         notes = NotebookNotes.query(ancestor = notebook.key).order(NotebookNotes.date).fetch()
     content = generic.render_str("notebook_printable.html",
                                  project = project, notebook = notebook, notes = notes)
     self.render("html_export.html", title = notebook.name, content = content)
Esempio n. 10
0
 def html_export(self, projectid, nbid):
     "Generates a printer-friendly version of the notebook."
     user = self.get_login_user()
     project = self.get_project(projectid)
     if not project:
         self.error(404)
         self.render("404.html", info = 'Project with key <em>%s</em> not found' % projectid)
         return
     notebook = self.get_notebook(project, nbid)
     if not notebook:
         self.error(404)
         self.render("404.html", info = 'Notebook with key <em>%s</em> not found' % nbid)
         return
     if not (notebook.is_open_p() or (user and project.user_is_author(user))):
         self.render("project_page_not_visible.html", project = project, user = user)
         return
     d = self.request.get("d")
     if d == "desc":
         notes = NotebookNotes.query(ancestor = notebook.key).order(-NotebookNotes.date).fetch()
     else:
         notes = NotebookNotes.query(ancestor = notebook.key).order(NotebookNotes.date).fetch()
     content = generic.render_str("notebook_printable.html",
                                  project = project, notebook = notebook, notes = notes)
     self.render("html_export.html", title = notebook.name, content = content)
Esempio n. 11
0
 def description_html(self, project, show_project_p=True):
     return generic.render_str("project_activity.html",
                               author=self.author.get(),
                               item=self.item,
                               project=project,
                               show_project_p=show_project_p)
Esempio n. 12
0
 def description_html(self, project, show_project_p = True):
     return generic.render_str("project_activity.html", author = self.author.get(), item = self.item, project = project, show_project_p = show_project_p)
Esempio n. 13
0
 def description_html(self, show_group_p = True):
     return generic.render_str("group_activity.html",
                               author = self.author.get(),
                               item = self.item,
                               group = self.key.parent().get())
Esempio n. 14
0
 def render(self):
     self._render_text = self.titulo
     return generic.render_str('libro.html', l = self)
Esempio n. 15
0
 def description_html(self, show_group_p = True):
     return generic.render_str("group_activity.html",
                               author = self.author.get(),
                               item = self.item,
                               group = self.key.parent().get())
Esempio n. 16
0
File: users.py Progetto: anando5/-e
 def post(self):
     action = self.request.get('action')
     have_error = False
     email = self.request.get("email")
     if action == "send_email":
         if (not email) or (not re.match(EMAIL_RE, email)):
             have_error = True
             r_error_message = "Please write a valid email."
         if not have_error:
             user = self.get_user_by_email(email)
             if not user:
                 have_error = True
                 r_error_message = "That's not a registered email."
         if have_error:
             self.redirect("/login?r_error_message=%s" % r_error_message)
         else:
             link = '%s/recover_password?email=%s&k=%s' % (
                 generic.APP_URL, email,
                 generic.hash_str(user.username + user.salt))
             message = mail.EmailMessage(
                 sender=generic.APP_NAME + ' <' + generic.ADMIN_EMAIL + '>',
                 to=email,
                 subject='Password recovery',
                 body=generic.render_str('emails/recover_password.txt',
                                         reset_link=link,
                                         ADMIN_EMAIL=generic.ADMIN_EMAIL),
                 html=generic.render_str('emails/recover_password.html',
                                         reset_link=link,
                                         ADMIN_EMAIL=generic.ADMIN_EMAIL))
             if generic.DEBUG:
                 logging.debug(
                     "EMAIL: Sending an email for password recovery. ")
             message.send()
             self.redirect(
                 '/login?info=Email sent. To reset your password follow the instructions on the email.'
             )
     elif action == "do_reset":
         password = self.request.get("password")
         p_repeat = self.request.get("p_repeat")
         key = self.request.get("k")
         if not (email and key):
             have_error = True
         if not (password and p_repeat and re.match(PASSWORD_RE, password)
                 and password == p_repeat):
             self.redirect(
                 '/recover_password?email=%s&k=%s&error=%s' %
                 (email, key,
                  "Please fill both boxes with the same password. "))
             return
         if not have_error:
             user = self.get_user_by_email(email)
             if not user:
                 have_error = True
             elif not key == generic.hash_str(user.username + user.salt):
                 have_error = True
         if have_error:
             self.error(400)
             error = "Invalid request. "
             self.write(error)
         else:
             salt = generic.make_salt()
             user.salt = salt
             user.password_hash = generic.hash_str(password + salt)
             self.log_and_put(user)
             self.redirect(
                 "/login?info=Password successfully changed, you can login now with your new password."
             )