Example #1
0
    def handle(self, action, user, workspace, actionManager):
        logManager.info("Execute registration action")
        replyActions = []
        userdata = action['userdata']
        if userManager.checkUserExist(userdata['email']):
            replyActions.append(
                webclientActions.NotificationAction.generate(
                    "User already exist", "error"))
        else:
            u = userManager.registerUser(userdata)
            link = generateActionLink(workspace, 'verifyUser',
                                      {'email': userdata['email']},
                                      "user/login", True, False)
            data = {
                'username': userdata['firstname'] + ' ' + userdata['lastname'],
                'action_link': link
            }
            send_mail([userdata['email']], "#Rosenwerk Account verifizieren",
                      workspace, 'requestVerification.mail', data)
            send_message(u, "Welcome", workspace, 'welcome.message', data,
                         'Roseguarden', False, 'welcome.mail')
            replyActions.append(
                webclientActions.NotificationAction.generate(
                    "User registered", "success"))
            replyActions.append(
                webclientActions.RouteAction.generate("dashboard", 3))

        return 'success', replyActions
Example #2
0
def test_get_user_messages(client: FlaskClient, admin_login):
    from core.messages import send_message
    from dal.user import User

    admin = User.query.filter_by(email='*****@*****.**').first()

    send_message(admin.id, 'testing a subject',
                 '<h1>Hello test</h1><p>This is the body</p>')

    resp = client.get(endpoint('/messages'), headers=admin_login)
    assert resp.status_code == 200
    assert 'list' in resp.json
    assert len(resp.json['list']) == 1
    assert 'subject' in resp.json['list'][0]
    assert 'id' in resp.json['list'][0]
    assert 'message' in resp.json['list'][0]
    assert 'read' in resp.json['list'][0]
    assert 'date' in resp.json['list'][0]
    assert resp.json['list'][0]['read'] == False
Example #3
0
def create_devEnv(app, db, clean=True):
    print()
    print("Create dev enviroment")
    if clean is True:
        PermissionGroup.query.delete()
        AccessgroupSpaceMap.query.delete()
        SpaceAccessGroup.query.delete()
        SpaceAccessSpace.query.delete()
        SpaceNodeMap.query.delete()
        ActionLink.query.delete()

    pAll = Permission.query.all()
    permissions = {}
    print('Detected permissions:')
    for p in pAll:
        permissions[p.name] = p

    pg = PermissionGroup(name='Supervisor')
    if 'Log.ViewLogs' in permissions:
        pg.permissions.append(permissions['Log.ViewLogs'])
    db.session.add(pg)

    usersWorkspace = workspaceManager.getWorkspace('Users')

    u = User.query.filter_by(email='*****@*****.**').first()
    if u is None:
        u = User(email='*****@*****.**', password='******', isAdmin=False)
        u.firstname = "Test"
        u.lastname = "User"
        u.organization = "Konglomerat"
        u.account_verified = True
        u.pin = "123456"
        workspaceManager.triggerWorkspaceHooks(WorkspaceHooks.CREATEUSER, user=u)
        db.session.add(u)
        data = {'username': u.firstname + " " + u.lastname}
        send_message(u, "Welcome", usersWorkspace, 'welcome.message', data, 'Roseguarden')

    s = User.query.filter_by(email='*****@*****.**').first()
    if s is None:
        s = User(email='*****@*****.**', password='******', isAdmin=False)
        s.firstname = "Super"
        s.lastname = "User"
        s.organization = "Konglomerat"
        s.account_verified = True
        s.pin = "123456"
        s.permission_groups.append(pg)
        workspaceManager.triggerWorkspaceHooks(WorkspaceHooks.CREATEUSER, user=s)
        db.session.add(s)
        data = {'username': s.firstname + " " + s.lastname}
        send_message(s, "Welcome", usersWorkspace, 'welcome.message', data, 'Roseguarden')

    a = User.query.filter_by(email='*****@*****.**').first()
    if a is None:
        a = User(email='*****@*****.**', password='******', isAdmin=True)
        a.firstname = "Test"
        a.lastname = "Admin"
        a.organization = "Konglomerat"
        a.account_verified = True
        a.pin = "123456"
        a.setAuthenticatorHash(b'$2b$12$zOn/sn5hpG02xpwvj74zruGHBGYCDgayBacy9Q9zBgM6.OEExh5Zm')
        a.authenticator_status = UserAuthenticatorStatus.VALID
        workspaceManager.triggerWorkspaceHooks(WorkspaceHooks.CREATEUSER, user=a)
        db.session.add(a)
        data = {'username': a.firstname + " " + a.lastname}
        send_message(a, "Welcome", usersWorkspace, 'welcome.message', data, 'Roseguarden')

    uva = User.query.filter_by(email='*****@*****.**').first()
    if uva is None:
        uva = User(email='*****@*****.**', password='******', isAdmin=True)
        uva.firstname = "Test"
        uva.lastname = "Unverifed"
        uva.organization = "Konglomerat"
        uva.account_verified = False
        uva.pin = "123456"
        workspaceManager.triggerWorkspaceHooks(WorkspaceHooks.CREATEUSER, user=uva)
        db.session.add(uva)
        data = {'username': uva.firstname + " " + uva.lastname}
        send_message(uva, "Welcome", usersWorkspace, 'welcome.message', data, 'Roseguarden')

    node_ident = {
        "nodename": "Door 1",
        "classname": "Door",
        "classworkspace": "Access",
        "classid": "00:01:AB:EF:19:D8:00:11",
        "firmware_version": "0.1.2",
        "firmware_compiled_at": "2007-12-22T18:21:01",
        "firmware_flashed_at": "2007-12-24T11:31:02",
        "hardware_version": "0.1.0"
    }
    node_fingerprint = "43:51:43:A1:B5:FC:8B:B7:0A:3A:A9:B1:0F:66:73:A8:73:A8:19:B1"
    node_authentification = "Kol-Bi-Hop-Ban-Gan-To-Sep+129"

    n = Node.query.filter_by(fingerprint=node_fingerprint).first()
    if n is None:
        nodeManager.create_node_from_identification(node_ident, node_fingerprint, node_authentification)
        nodeManager.authorizeNode(node_fingerprint)
        n = Node.query.filter_by(fingerprint=node_fingerprint).first()

    sas = SpaceAccessSpace(name="Garage workshop")
    sas.description = "The garage workshop"
    sas.entrance_nodes = [n]
    db.session.add(sas)

    ag = SpaceAccessGroup(name="Friends (full access)")
    ag.spaces = [sas]

    s = User.query.filter_by(email='*****@*****.**').first()
    if s is not None:
        ag.users.append(s)
    if a is not None:
        ag.users.append(a)

    ag.note = "Friends with full access"
    ag.access_type = SpaceAccessType.UNLIMITED
    ag.daily_access_start_time = arrow.get('00:00', 'HH:mm')
    ag.daily_access_end_time = arrow.get('23:59', 'HH:mm')
    ag.door_access_mask = 3
    ag.day_access_mask = 127
    ag.access_expires_as_default = False
    ag.access_expires_default_days = 365
    db.session.add(ag)

    # p = Permission(user=s, name= ViewLogs)
    pAll = Permission.query.all()
    print(pAll)

    # send_mail(["*****@*****.**"], "Welcome", usersWorkspace, 'welcome.mail', data )
    # print(generateActionLink(usersWorkspace, 'verifyUser', { 'email' : "*****@*****.**" }, "dashboard"))

    db.session.commit()

    # userManager.removeUser('*****@*****.**')

    all_user = User.query.all()
    print(all_user)
    for user in all_user:
        print(f' User: {user} {user.password} ')

    print("n")

    print(jobManager)
Example #4
0
 def post(self):
     send_message(**request.json)
     return Result.success()