def reset_password(request): loginhash = request.matchdict['loginhash'] users = User().queryObject().all() for user in users: if sha512(user.login).hexdigest() == loginhash: new_password = rand_string(10) logger.info('Password of user ' + user.login + ' has been reset to ' + new_password) user.password = sha512(new_password).hexdigest() user.save() localizer = get_localizer(request) # Create the body of the message (a plain-text and an HTML version) url = request.route_url('login') text_ts = _('plain_password_reset_mail', mapping={ 'name': user.name, 'password': new_password, 'url': url}, domain='Ondestan') html_ts = _('html_password_reset_mail', mapping={'name': user.name, 'password': new_password, 'url': url}, domain='Ondestan') subject_ts = _('subject_password_reset_mail', domain='Ondestan') text = localizer.translate(text_ts) html = localizer.translate(html_ts) subject = localizer.translate(subject_ts) send_mail(html, text, subject, user.email) break
def notify_new_order_to_admin_by_email(order_state, request): admin_email = Config.get_string_value('config.admin_email') if admin_email != None and admin_email != '': localizer = get_localizer(request) # Create the body of the message (a plain-text and an HTML version). text_ts = _('plain_new_order_admin_mail', mapping={'name': order_state.order.user.name, 'login': order_state.order.user.login, 'units': order_state.order.units, 'address': order_state.order.address, 'url': request.route_url('orders'), 'state': _('order_state_0', domain='Ondestán')}, domain='Ondestan') html_ts = _('html_new_order_admin_mail', mapping={'name': order_state.order.user.name, 'login': order_state.order.user.login, 'units': order_state.order.units, 'address': order_state.order.address, 'url': request.route_url('orders'), 'state': _('order_state_0', domain='Ondestán')}, domain='Ondestan') subject_ts = _('subject_new_order_admin_mail', domain='Ondestan') text = localizer.translate(text_ts) html = localizer.translate(html_ts) subject = localizer.translate(subject_ts) send_mail(html, text, subject, admin_email)
def notify_order_update_to_user_by_email(order_state, request): localizer = get_localizer(request) # Create the body of the message (a plain-text and an HTML version). text_ts = _('plain_order_update_user_mail', mapping={'name': order_state.order.user.name, 'login': order_state.order.user.login, 'units': order_state.order.units, 'address': order_state.order.address, 'url': request.route_url('orders'), 'state': localizer.translate(_('order_state_' + str(order_state.state), domain='Ondestan'))}, domain='Ondestan') html_ts = _('html_order_update_user_mail', mapping={'name': order_state.order.user.name, 'login': order_state.order.user.login, 'units': order_state.order.units, 'address': order_state.order.address, 'url': request.route_url('orders'), 'state': localizer.translate(_('order_state_' + str(order_state.state), domain='Ondestan'))}, domain='Ondestan') subject_ts = _('subject_order_update_user_mail', domain='Ondestan') text = localizer.translate(text_ts) html = localizer.translate(html_ts) subject = localizer.translate(subject_ts) send_mail(html, text, subject, order_state.order.user.email)
def create_user(request): localizer = get_localizer(request) login = request.params['login'] name = request.params['name'] email = request.params['email'] user = User().queryObject().filter(User.login == login).scalar() if (user != None): msg = _('login_already_use', domain='Ondestan') return localizer.translate(msg) user = User().queryObject().filter(User.email == email).scalar() if (user != None): msg = _('email_already_use', domain='Ondestan') return localizer.translate(msg) # Create the body of the message (a plain-text and an HTML version). url = request.route_url('activate_user', loginhash=sha512(login).hexdigest()) text_ts = _('plain_signup_mail', mapping={'name': name, 'url': url}, domain='Ondestan') html_ts = _('html_signup_mail', mapping={'name': name, 'url': url}, domain='Ondestan') subject_ts = _('subject_signup_mail', domain='Ondestan') text = localizer.translate(text_ts) html = localizer.translate(html_ts) subject = localizer.translate(subject_ts) send_mail(html, text, subject, email) user = User() user.login = login user.name = name user.email = email user.phone = request.params['phone'] user.activated = False user.password = sha512(request.params['password']).hexdigest() user.role_id = 2 user.save() return ''
def remind_user(request): email = request.params['email'] user = User().queryObject().filter( User.email == email).scalar() if (user != None): localizer = get_localizer(request) # Create the body of the message (a plain-text and an HTML version). url = request.route_url('password_reset', loginhash=sha512(user.login).hexdigest()) text_ts = _('plain_reminder_mail', mapping={'name': user.name, 'url': url, 'login': user.login}, domain='Ondestan') html_ts = _('html_reminder_mail', mapping={'name': user.name, 'url': url, 'login': user.login}, domain='Ondestan') subject_ts = _('subject_reminder_mail', domain='Ondestan') text = localizer.translate(text_ts) html = localizer.translate(html_ts) subject = localizer.translate(subject_ts) send_mail(html, text, subject, email)