def test_post_invite(self):
        sender = User(self.email, name="Bob")
        sender.create()
        recipient = User(self.random_email(), name="Alice")
        recipient.invite()
        invite = Invite(sender.email, recipient.email)
        res = invite.create()
        self.assertEqual(res.json()["success"], True)

        expected_inner_keys = ("id", "recipient", "sender", "sent_on", \
                "accepted_on", "sender_name", "recipient_name", \
                "status", "expire_on", "max_time_allowed", "notify_when")

        self.assertEqual(set(res.json()['invite'].keys()),
                         set(expected_inner_keys))

        self.assertEqual(res.json()['invite']['recipient'], recipient.email)
        self.assertEqual(res.json()['invite']['sender'], sender.email)
        self.assertEqual(res.json()['invite']['recipient_name'],
                         recipient.name)
        self.assertEqual(res.json()['invite']['sender_name'], sender.name)
        self.assertEqual(True, res.json()['invite']['accepted_on'] is None)
        self.assertEqual(True, res.json()['invite']['sent_on'] is not None)
        self.assertEqual(True, res.json()['invite']['id'] is not None)
        # issue 172
        self.assertEqual(res.json()['invite']['status'], 'pending')
    def test_get_all_invites(self):
        # create a couple invitations and GET /invites should
        # return all the invitations in the system
        recipient1 = User(self.random_email())
        recipient1.invite()
        recipient2 = User(self.random_email())
        recipient2.invite()
        recipient3 = User(self.random_email())
        recipient3.invite()

        sender = User(self.random_email())
        sender.create()

        invite1 = Invite(sender.email, recipient1.email)
        invite1.create()
        invite2 = Invite(sender.email, recipient2.email)
        invite2.create()
        invite3 = Invite(sender.email, recipient3.email)
        invite3.create()

        res = Invites().get()
        self.assertEqual(len(res.json()['invites']), 3)
        self.assertEqual(res.json()['invites'][0]['recipient'],
                         recipient1.email)
        self.assertEqual(res.json()['invites'][1]['recipient'],
                         recipient2.email)
        self.assertEqual(res.json()['invites'][2]['recipient'],
                         recipient3.email)
    def test_delete_not_used_invitation(self):
        recipient = User(self.random_email())
        recipient.invite()
        sender = User(self.random_email())
        sender.create()

        invite = Invite(sender.email, recipient.email)
        res1 = invite.create()
        invite_id = res1.json()["invite"]["id"]

        # create a group in minion that includes the recipient (bug#175)
        group = Group(self.group_name, users=[recipient.email])
        group.create()

        # ensure now the recipient is part of the new group
        res2 = recipient.get()
        self.assertEqual(res2.json()['user']['groups'], [group.group_name])
        # also, this user is still marked as "invited"
        self.assertEqual(res2.json()['user']['status'], 'invited')

        # admin deletes this invitation off minion
        res3 = invite.delete(invite_id)
        self.assertEqual(res3.json()["success"], True)

        # since invitation is gone, user should be gone too
        res4 = recipient.get()
        self.assertEqual(res4.json()['success'], False)
        self.assertEqual(res4.json()['reason'], 'no-such-user')

        # recipient is also gone from any group association
        res5 = group.get()
        self.assertEqual(res5.json()['group']['users'], [])
    def test_decline_invite(self):
        recipient = User(self.random_email())
        recipient.invite()
        sender = User(self.random_email())
        sender.create()

        invite = Invite(sender.email, recipient.email)
        res1 = invite.create()
        invite_id = res1.json()["invite"]["id"]

        # create a group in minion that includes the recipient (bug#175)
        group = Group(self.group_name, users=[recipient.email])
        group.create()

        # ensure now the recipient is part of the new group
        res2 = recipient.get()
        self.assertEqual(res2.json()['user']['groups'], [group.group_name])

        # recipient has declined the invitation
        res3 = invite.update(invite_id, "decline", login=recipient.email)
        self.assertEqual(res3.json()['invite']['status'], 'declined')

        # when recipient declined, user account is deleted (bug #175)
        res4 = recipient.get()
        self.assertEqual(res4.json()['success'], False)
        self.assertEqual(res4.json()['reason'], 'no-such-user')

        # when recipient declined, user is also not part of a group anymore (bug #175)
        res5 = group.get()
        self.assertEqual(res5.json()['group']['users'], [])
    def test_accept_invite_with_a_different_login_email(self):
        # we allow recipient to login with a different email address.
        recipient = User(self.random_email())
        recipient.invite()
        sender = User(self.random_email())
        sender.create()

        invite = Invite(sender.email, recipient.email)
        res1 = invite.create()
        invite_id = res1.json()["invite"]["id"]

        # create a group and a site and add the recipient to the group
        site = Site(self.target_url)
        res2 = site.create()

        # create a group in minion
        group = Group(self.group_name,
                      sites=[site.url],
                      users=[recipient.email])
        group.create()

        # ensure user and site are in this new group
        res3 = group.get()
        self.assertEqual(res3.json()["group"]["sites"], [site.url])
        self.assertEqual(res3.json()["group"]["users"], [recipient.email])

        # user should have access to the group and the site
        res4 = recipient.get()
        self.assertEqual(res4.json()["user"]["sites"], [site.url])
        self.assertEqual(res4.json()["user"]["groups"], [group.group_name])

        # recipient accepts the invitation with a different login email address
        actual_login = self.random_email()
        recipient_2 = User(actual_login)
        res5 = invite.update(invite_id, "accept", login=recipient_2.email)
        self.assertEqual(res5.json()["success"], True)

        # upon invitation acceptance, user status changed to active
        res6 = recipient_2.get()
        self.assertEqual(res6.json()['user']['email'], recipient_2.email)
        self.assertEqual(res6.json()['user']['status'], 'active')
        # the new email address has access to the group and site
        self.assertEqual(res6.json()["user"]["groups"], [group.group_name])
        self.assertEqual(res6.json()["user"]["sites"], [site.url])

        # if we query the old recipient email, it should not be found
        res7 = recipient.get()
        self.assertEqual(res7.json()["success"], False)
        self.assertEqual(res7.json()["reason"], "no-such-user")

        # group should agree that user and site are still member of the group
        res8 = group.get()
        self.assertEqual(res8.json()["group"]["sites"], [site.url])
        self.assertEqual(res8.json()["group"]["users"], [recipient_2.email])
    def test_invite_an_existing_user(self):
        sender = User(self.email)
        sender.create()
        recipient = User(self.random_email(), name="Alice")
        # don't invite, do a physical creation
        recipient.create()

        # try invite recipient even though recipient is an active member
        invite = Invite(sender.email, recipient.email)
        res = invite.create()
        self.assertEqual(res.json()['success'], False)
        self.assertEqual(res.json()['reason'], 'recipient-already-joined')
    def test_create_group_with_existing_user(self):
        bob = User(self.email)
        bob.create()
        alice = User("*****@*****.**")
        alice.create()

        group = Group(self.group_name, users=[bob.email, alice.email])
        res = group.create()

        self.assertEqual(res.json()['success'], True)
        self.assertEqual(set(res.json()['group']['users']),
                         set([alice.email, bob.email]))
    def test_get_invites_filter_by_sender_and_or_recipient(self):
        # recipient1 will be invited by sender1
        # recipient2 and 3 will be invited by sender23
        recipient1 = User(self.random_email())
        recipient1.invite()
        recipient2 = User(self.random_email())
        recipient2.invite()
        recipient3 = User(self.random_email())
        recipient3.invite()

        sender1 = User(self.random_email())
        sender1.create()
        sender23 = User(self.random_email())
        sender23.create()

        invite1 = Invite(sender1.email, recipient1.email)
        invite1.create()
        invite2 = Invite(sender23.email, recipient2.email)
        invite2.create()
        invite3 = Invite(sender23.email, recipient3.email)
        invite3.create()

        # recipient1 should be given filter=sender1
        res1 = Invites().get(sender=sender1.email)
        self.assertEqual(len(res1.json()['invites']), 1)
        self.assertEqual(res1.json()['invites'][0]['recipient'],
                         recipient1.email)
        self.assertEqual(res1.json()['invites'][0]['sender'], sender1.email)

        # recipient2 and 3 are returned given filter=sender23
        res2 = Invites().get(sender=sender23.email)
        self.assertEqual(len(res2.json()['invites']), 2)
        self.assertEqual(res2.json()['invites'][0]['recipient'],
                         recipient2.email)
        self.assertEqual(res2.json()['invites'][1]['recipient'],
                         recipient3.email)

        # no recipient is returned given filter=unknwon
        res3 = Invites().get(sender="*****@*****.**")
        self.assertEqual(len(res3.json()['invites']), 0)

        # recipient1 is returned given filter recipient=recipient1
        res4 = Invites().get(recipient=recipient1.email)
        self.assertEqual(len(res4.json()['invites']), 1)
        self.assertEqual(res4.json()['invites'][0]['recipient'],
                         recipient1.email)

        # recipient2 is returned given filter recipient=recipient2 and sender=sender23
        res5 = Invites().get(recipient=recipient2.email, sender=sender23.email)
        self.assertEqual(len(res5.json()['invites']), 1)
        self.assertEqual(res5.json()['invites'][0]['recipient'],
                         recipient2.email)
    def test_resend_invite(self):
        recipient = User(self.random_email())
        recipient.invite()

        sender = User(self.random_email())
        sender.create()

        invite = Invite(sender.email, recipient.email)
        res1 = invite.create()
        self.assertEqual(res1.json()["success"], True)
        old_invite_id = res1.json()["invite"]["id"]

        # resent invitation to recipient should produce a new invitiation id
        res2 = invite.update(old_invite_id, "resend", login=recipient.email)
        self.assertNotEqual(res2.json()['invite']['id'], old_invite_id)
    def test_duplicate_invitations(self):
        sender = User(self.email)
        sender.create()
        recipient = User(self.random_email(), name="Alice")
        recipient.invite()

        # send first invitation to recipient
        invite = Invite(sender.email, recipient.email)
        res = invite.create()
        self.assertEqual(res.json()["success"], True)

        # send a second invitation to recipient
        res2 = invite.create()
        self.assertEqual(res2.json()['success'], False)
        self.assertEqual(res2.json()['reason'],
                         'duplicate-invitation-not-allowed')
 def test_get_all_groups(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     res1 = group.create()
     res2 = Groups().get()
     self.assertEqual(res2.json()['groups'][0], res1.json()['group'])
    def test_update_user(self):
        group1 = Group("group1")
        group2 = Group("group2")
        group1.create()
        group2.create()

        # Create a user
        bob = User(self.email,
                   name="Bob",
                   role="user",
                   groups=[group1.group_name])
        res2 = bob.create()
        self.assertEqual(res2.json()['user']['email'], bob.email)
        self.assertEqual(res2.json()['user']['groups'], [group1.group_name])
        self.assertEqual(res2.json()["user"]["role"], "user")

        # Update the user
        res3 = bob.update(name="Bobby",
                          role="administrator",
                          groups=[group2.group_name])
        self.assertEqual(res3.json()["success"], True)
        self.assertEqual(res3.json()['user']['email'], bob.email)
        self.assertEqual(res3.json()['user']['name'], bob.name)
        self.assertEqual(res3.json()['user']['groups'], [group2.group_name])
        self.assertEqual(res3.json()["user"]["role"], "administrator")

        # Make sure the user stored in the db is correct
        res4 = bob.get()
        self.assertEqual(res4.json()['success'], True)
        self.assertEqual(res4.json()['user']['email'], bob.email)
        self.assertEqual(res4.json()['user']['name'], bob.name)
        self.assertEqual(res4.json()['user']['groups'], [group2.group_name])
        self.assertEqual(res4.json()['user']['role'], "administrator")
 def test_delete_group(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     group.create()
     res = group.delete()
     self.assertEqual(res.json()['success'], True)
    def test_fetch_invite_by_id(self):
        recipient = User(self.random_email())
        recipient.invite()

        sender = User(self.random_email())
        sender.create()

        invite = Invite(sender.email, recipient.email)
        res = invite.create()
        self.assertEqual(res.json()["success"], True)
        invite_id = res.json()["invite"]["id"]

        res2 = invite.get(invite_id)
        self.assertEqual(res2.json()['invite']['recipient'], recipient.email)
        self.assertEqual(res2.json()['invite']['sender'], sender.email)
        self.assertEqual(res2.json()['invite']['id'], invite_id)
 def test_patch_group_add_site(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     res1 = group.create()
     res2 = group.update(add_sites=[self.target_url])
     self.assertEqual(res2.json()['group']['sites'][0], self.target_url)
 def test_update_invited_user(self):
     #self.start_smtp()
     bob = User(self.email)
     res1 = bob.invite()
     res2 = bob.update(status="active")
     self.assertEqual(res2.json()['user']['status'], 'active')
     self.assertEqual(res1.json()['user']['status'], 'invited')
 def test_invite_user(self):
     #self.start_smtp()
     bob = User(self.email)
     res = bob.invite()
     self.assertEqual(set(res.json()['user'].keys()),
                      set(self.expected_inner_keys))
     self.assertEqual(res.json()['user']['status'], 'invited')
 def test_patch_group_remove_user(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name, users=[bob.email])
     res1 = group.create()
     res2 = group.update(remove_users=[bob.email])
     self.assertEqual(res2.json()['group']['users'], [])
Exemple #19
0
def createUser(login_session):
    newUser = User(name=login_session['username'], email=login_session[
        'email'], picture=login_session['picture'])
    session.add(newUser)
    session.commit()
    user = session.query(User).filter_by(email=login_session['email']).one()
    return user.id
Exemple #20
0
def init_data():
    """Fish data for project"""
    db.drop_all()
    db.create_all()

    user = User(username='******', email='*****@*****.**', password='******')
    user.save()
 def test_delete_unknown_user(self):
     random_user = User("*****@*****.**")
     r = random_user.delete()
     self.assertEqual({
         'success': False,
         'reason': 'no-such-user'
     }, r.json())
def createTeacher(info_dict):

    name = info_dict['tc_name']
    username = info_dict['tc_id']
    passkey = info_dict['tc_pass']
    subject = info_dict['tc_course']
    newTeacher = Teachers(name=name, id=username)
    newUser = User(id=username, pwd=passkey, role='Teacher')

    for key, pair in info_dict.items():

        if key.startswith('Section_name'):
            sec = pair
            sem = info_dict[f'Semester_name{key[12:]}']

            classroom = Class.query.filter_by(section=sec,
                                              semester=sem).first()
            sub = Subject.query.filter_by(name=subject).first()

            if classroom == None:
                classroom = createClass(sec, sem)

            if sub == None:
                sub = createSubject(subject)

            classroom.subjects.append(sub)
            newTeacher.classes.append(classroom)
            newTeacher.subject = sub.id

    db.session.add(newTeacher)
    db.session.add(newUser)
    db.session.commit()
def start(bot, update):
	id = update.message.chat.id
	if id > 0: # groups ignored
		keyboard = [['Status', 'Media'], 
			        ['Settings', 'Chat'], 
			        ['Referral link']]
		reply_markup = ReplyKeyboardMarkup(keyboard, resize_keyboard=True)
		welcome_text = '''Welcome to the AIRDROP CTLgroup bot!
						To get 25 CTLcoin please do the following:
						- specify in the bot settings the links to your reposts from our Facebook and Twitter pages
						- subscribe to our telegram channel @CryptoTradeLine and go to chat
						To get additional tokens invite your friends to the bot and get 1 CTLcoin for each one connected to the bot'''
		bot.send_message(chat_id=id, text=welcome_text, reply_markup=reply_markup)
		msg = update.message.text.replace('/start', '').strip()
		entered_user = User.query.filter(User.id==id).first()
		if entered_user == None:

			db_session.add(User(id=id, name=update.message.chat.username, inviter=msg))
			db_session.commit()
			print('commited')
			if msg != '' and msg != str(id):
				bonus = 1
				inviter = User.query.filter(User.id==msg).first()
				inviter.tokens_acc += bonus
				inviter.refs += 1
				tokens_left = Parametr.query.filter(Parametr.parametr=='Tokens_left').first()
				tokens_left.value_flt -= bonus
				db_session.commit()
				bot.send_message(chat_id=msg, text='+ %s tokens for friend inviting ' % bonus + update.message.chat.first_name)
			elif msg == str(id):
				update.message.text_reply('You have received a link to yourself, do /start')
		elif msg == str(id):
			bot.send_message(chat_id=id, text='You invited yourself')
Exemple #24
0
def init_data():
    """Fish data for project"""
    db.drop_all()
    db.create_all()

    admin = User(username=app.config['ADMIN_USERNAME'], email=app.config['ADMIN_EMAIL'], password=app.config['ADMIN_PASSWORD'])
    admin.save()
Exemple #25
0
def register():
    if request.method == "POST":
        name = request.form['name']
        login = request.form['login']
        password = request.form['password']
        token = hashlib.md5(bytes(random.randint(1, 10000000))).hexdigest()
        expiration = (datetime.now() + timedelta(days=30))
        user_id = int(User.query.order_by(User.id.desc()).first().id) + 1
        newUser = User(id=user_id,
                       name=name,
                       login=login,
                       password=password,
                       token=token,
                       expiration=expiration)

        if userReg(login):
            try:
                db.session.add(newUser)
                db.session.commit()
                return redirect('/')
            except:
                return print("При добавлении возникла ошибка")
        else:
            print('Not unique login')
    return render_template('register.html')
 def test_patch_group_add_user(self):
     bob = User(self.email)
     bob.create()
     group = Group(self.group_name)
     group.create()
     res = group.update(add_users=[bob.email])
     self.assertEqual(res.json()['group']['users'], group.users)
Exemple #27
0
 def has_permission(self, per_name):
     self.user = User(self.user.username)
     if self.user.permission is not None and self.user.permission.get(
             per_name) == 1:
         return True
     else:
         return False
Exemple #28
0
    def __init__(self, Parent, Query=None):
        QtGui.QDialog.__init__(self, Parent)
        self.setWindowTitle(d2u("Корисници"))
        self.setWindowIcon(QtGui.QIcon("static/icons/User.ico"))

        self.Query = Query
        self.User = User()

        mainLayout = QtGui.QVBoxLayout(self)

        self.listUsers = QtGui.QListWidget()
        self.listUsers.setSortingEnabled(True)

        self.textName = QtGui.QLineEdit(self)
        self.textName.setPlaceholderText(d2u('Корисничко име'))
        self.textName.setFixedWidth(200)

        self.textPass = QtGui.QLineEdit(self)
        self.textPass.setPlaceholderText(d2u('Лозинка'))
        self.textPass.setEchoMode(QtGui.QLineEdit.Password)
        self.textPass.setFixedWidth(200)

        self.buttonSignIn = QtGui.QPushButton(d2u('Создади'), self)
        self.buttonSignIn.setFixedWidth(200)
        self.buttonSignIn.clicked.connect(self.SignInClicked)

        self.buttonDelete = QtGui.QPushButton(d2u('Избриши'), self)
        self.buttonDelete.setFixedWidth(200)
        self.buttonDelete.clicked.connect(self.DeleteClicked)

        #layout
        signIn = QtGui.QVBoxLayout()
        self.groupBox1 = QtGui.QGroupBox(d2u('Создади нов корисник'))
        self.groupBox2 = QtGui.QGroupBox(
            d2u('Избриши го селектираниот корисник'))
        signIn.addWidget(self.textName)
        signIn.addWidget(self.textPass)
        signIn.addWidget(self.buttonSignIn)
        signIn.addStretch()
        self.groupBox1.setLayout(signIn)

        delete = QtGui.QVBoxLayout()
        delete.addWidget(self.buttonDelete)
        self.groupBox2.setLayout(delete)

        right = QtGui.QVBoxLayout()
        right.addWidget(self.groupBox1)
        right.addWidget(self.groupBox2)

        users = QtGui.QHBoxLayout()
        users.addWidget(self.listUsers)
        users.addLayout(right)

        mainLayout.addLayout(users)
        self.FillUsersList()
        self.setLayout(mainLayout)

        self.sign = 0
        self.delete = 0
def createStudent(name, usrname, passkey, sec, sem):

    newUser = User(id=usrname, pwd=passkey, role='Student')
    clssroom = Class.query.filter_by(section=sec, semester=sem).first()
    newStudent = Students(name=name, id=usrname, classroom=clssroom)
    db.session.add(newUser)
    db.session.add(newStudent)
    db.session.commit()
    def test_get_all_users(self):
        bob = User(self.email)
        bob.create()

        res = Users().get()
        _expected = list(self.expected_inner_keys) + ["sites"]
        self.assertEqual(set(res.json()['users'][0].keys()), set(_expected))
        self.assertEqual(1, len(res.json()['users']))