コード例 #1
0
ファイル: routes.py プロジェクト: Ulrich-F/do-portal
def unregister():
    """Unregister CP account

    User will be removed from :class:`app.models.User` and
    :attr:`~app.models.ContactEmail.cp` will be disabled.

    .. note::

        The email address will NOT be deleted from :class:`~app.models.Email`.

    **Example request**:

    .. sourcecode:: http

        POST /api/1.0/auth/unregister HTTP/1.1
        Host: do.cert.europa.eu
        Accept: application/json

        {
          "organization_id": 317,
          "name": "BEREC ([email protected])",
          "email": "*****@*****.**"
        }

    **Example response**:

    .. sourcecode:: http

        HTTP/1.0 200 OK
        Content-Type: application/json

        {
          "message": "User has been unregistered. A notification has been..."
        }

    :reqheader Accept: Content type(s) accepted by the client
    :resheader Content-Type: this depends on `Accept` header or request

    :>json integer organization_id: Organization unique ID
    :>json string name: Name of account
    :>json string email: E-mail address

    :status 200: Account has been unregistered.
    """
    eml = ContactEmail.query.filter_by(
        email=request.json['email'],
        organization_id=request.json['organization_id']).first()
    eml.cp = False
    db.session.add(eml)

    user = User.query.filter_by(email=request.json['email']).first()
    send_email('Your account details', [user.email],
               'auth/email/deactivate_account',
               user=user)
    notify = user.email
    User.query.filter_by(email=request.json['email']).delete()
    db.session.commit()
    msg = 'User has been unregistered. A notification has been sent to {}'
    return ApiResponse({'message': msg.format(notify)})
コード例 #2
0
def _send_reset_password_email(email):
    key = __key_reset_password_code(email)
    reset_password_code = shortuuid.uuid()

    redis_cli.setex(key, timedelta(hours=1), reset_password_code)
    reset_password_url = url_for('user.reset_password_page',
                                 e=base64.urlsafe_b64encode(email),
                                 c=reset_password_code,
                                 _external=True)
    send_email(email,
               u'重置密码',
               'reset_password.html',
               reset_password_url=reset_password_url)
コード例 #3
0
def _send_activate_email(email):
    key = __key_activate_email_code(email)
    activate_code = shortuuid.uuid()

    redis_cli.setex(key, timedelta(days=1), activate_code)
    activate_url = url_for('user.activate_email',
                           e=base64.urlsafe_b64encode(email),
                           c=activate_code,
                           _external=True)
    send_email(email,
               u'邮箱激活',
               'activate_email.html',
               activate_url=activate_url)
コード例 #4
0
ファイル: routes.py プロジェクト: Ulrich-F/do-portal
def register():
    """Register new constituent account

    .. note::

        The email address will be added to :class:`~app.models.Email` and
        :attr:`~app.models.ContactEmail.cp` will be enabled.

    **Example request**:

    .. sourcecode:: http

        POST /api/1.0/auth/register HTTP/1.1
        Host: do.cert.europa.eu
        Accept: application/json

        {
          "organization_id": 317,
          "name": "BEREC ([email protected])",
          "email": "*****@*****.**"
        }

    **Example response**:

    .. sourcecode:: http

        HTTP/1.0 201 CREATED
        Content-Type: application/json

        {
          "message": "User registered. An activation email was sent to ..."
        }

    :reqheader Accept: Content type(s) accepted by the client
    :resheader Content-Type: this depends on `Accept` header or request

    :>json integer organization_id: Organization unique ID
    :>json string name: Name of account
    :>json string email: E-mail address

    :status 201: Account created.
    """
    org = Organization.query.filter_by(id=request.json['organization_id']).\
        first_or_404()
    eml = ContactEmail.query.filter_by(
        email=request.json['email'],
        organization_id=request.json['organization_id']).first()
    if not eml:
        eml = ContactEmail.fromdict(request.json)
    eml.cp = True

    user = User.fromdict(request.json)
    user.password = _random_ascii()
    user.api_key = user.generate_api_key()
    if org.is_sla:
        roles = Role.query.filter(db.not_(Role.permissions == 0xff)).all()
        for role in roles:
            if ((role.permissions
                 & Permission.SLAACTIONS) == Permission.SLAACTIONS):
                user.role = role
                break
    db.session.add(user)
    db.session.add(eml)
    try:
        db.session.commit()
    except Exception as e:
        db.session.rollback()
        db.session.flush()
        raise e
    expiry = 72 * 3600
    activation_token = user.generate_reset_token(expiry)
    send_email('Your account details', [user.email],
               'auth/email/activate_account',
               user=user,
               webroot=current_app.config['CP_WEB_ROOT'],
               token=activation_token,
               expiry=expiry / 60)
    msg = 'User registered. An activation email was sent to {}'
    return ApiResponse({'message': msg.format(user.email)}, 201)