Exemplo n.º 1
0
def update_user(request):
    localizer = get_localizer(request)

    user_id = int(request.params['id'])
    login = request.params['login']
    name = request.params['name']
    email = request.params['email']
    user = User().queryObject().filter(User.login == login).scalar()
    if ((user != None) and (user.id != user_id)):
        msg = _('login_already_use', domain='Ondestan')
        return localizer.translate(msg)
    user = User().queryObject().filter(User.email == email).scalar()
    if ((user != None) and (user.id != user_id)):
        msg = _('email_already_use', domain='Ondestan')
        return localizer.translate(msg)
    user = User().queryObject().filter(User.id == user_id).scalar()
    user.login = login
    user.name = name
    user.email = email
    user.phone = request.params['phone']
    user.password = sha512(request.params['password']).hexdigest()
    user.update()

    msg = _('user_profile_updated', domain='Ondestan')
    return localizer.translate(msg)
Exemplo n.º 2
0
def update_user(request):
    user_id = int(request.params['id'])
    user = User().queryObject().filter(User.id == user_id).scalar()
    if (user.email != get_user_email(request)):
        return
    name = request.params['name']
    email = request.params['email']
    user = User().queryObject().filter(User.email == email).scalar()
    if ((user != None) and (user.id != user_id)):
        notification = Notification()
        notification.text = "_('email_already_use', domain='Ondestan')"
        notification.level = 3
        return notification

    user = User().queryObject().filter(User.id == user_id).scalar()
    user.name = name
    user.email = email
    user.phone = request.params['phone']
    user.update()
    logger.debug('Profile updated for user ' + user.email)

    notification = Notification()
    notification.text = "_('user_profile_updated', domain='Ondestan')"
    notification.level = 0
    return notification
Exemplo n.º 3
0
def update_password(request):
    user_id = int(request.params['id'])
    user = User().queryObject().filter(User.id == user_id).scalar()
    if (user.email != get_user_email(request)):
        return
    old_password = request.params['old_password']

    if user.password != sha512(old_password).hexdigest():
        notification = Notification()
        notification.text = "_('wrong_password', domain='Ondestan')"
        notification.level = 3
        return notification
    user.password = sha512(request.params['password']).hexdigest()
    user.update()
    logger.debug('Password updated for user ' + user.email)

    notification = Notification()
    notification.text = "_('user_password_updated', domain='Ondestan')"
    notification.level = 0
    return notification
Exemplo n.º 4
0
def create_order(request):
    email = get_user_email(request)
    units = int(request.params['units'])
    address = request.params['address']
    user = User().queryObject().filter(User.email == email).scalar()
    if (user != None):
        order = Order()
        order.units = units
        order.address = address
        order.user_id = user.id
        order.save()

        order_state = Order_state()
        order_state.order_id = order.id
        order_state.state = Order_state._STATES[0]
        order_state.date = datetime.utcnow()
        order_state.save()

        notify_new_order(order_state, request)

    return ''
Exemplo n.º 5
0
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 ''
Exemplo n.º 6
0
def create_user(request):
    localizer = get_localizer(request)

    name = request.params['name']
    email = request.params['email']
    user = User().queryObject().filter(User.email == email).scalar()
    if (user != None):
        msg = _('email_already_use', domain='Ondestan')
        return localizer.translate(msg)

    user = User()
    user.name = name
    user.email = email
    user.locale = get_locale_name(request)
    user.phone = request.params['phone']
    user.activated = False
    user.password = sha512(request.params['password']).hexdigest()
    user.role_id = 2
    user.save()

    url = request.route_url('activate_user',
                            loginhash=sha512(email).hexdigest())
    parameters = {'name': name, 'url': url}
    ondestan.services.notification_service.process_notification('signup',
        user.email, False, 0, True, False, parameters)

    return ''