Exemplo n.º 1
0
    def get(self, room_name):
        if self.does_room_exist(room_name):
            if user_help.get_user_email():
                if self.is_user_allowed_in_room(user_help.get_user_email(), room_name):
                    (client_id, token) = token_help.generate_token()
                    user = CryptChatUser.query(user_help.get_user_email() == CryptChatUser.email).fetch()
                    client_e, client_n = "", ""
                    if len(user) > 0:
                        client_e = user[0].e
                        client_n = user[0].n
                    clients.add_connected(client_id, room_name, client_e, client_n)

                    template_params = {
                        'client_id': client_id,
                        'send_url': '/room/' + room_name,
                        'room_name': room_name,
                        'token': token
                    }
                    template_help.render_template(self, 'room.html', template_params)
                else:
                    self.redirect('/error')
            else:
                self.redirect('/')
        else:
            self.redirect('/404')
Exemplo n.º 2
0
def is_user_authenticated(user_email):
    if user_email is None:
        return False
    q = CryptChatUser.query(CryptChatUser.email == user_email)
    entity = q.get()
    if entity.e == None or entity.n == None:
        return False
    else:
        return True
Exemplo n.º 3
0
 def get(self, room_name):
     user = CryptChatUser.query(user_help.get_user_email() == CryptChatUser.email).fetch()
     client_e, client_n = "", ""
     if len(user) > 0:
         client_e = user[0].e
         client_n = user[0].n
     (client_id, tok) = token_help.generate_token()
     # Find a way to get room number here
     clients.add_connected(client_id, room_name, client_e, client_n)
     self.response.write(tok)
Exemplo n.º 4
0
 def get(self, num):
     senderEmail = user_help.get_user_email()
     q = CryptChatUser.query(CryptChatUser.email == senderEmail)
     ccuser = q.get() #should be fine bc just one user assc with email
     ccuser.avatar = num
     ccuser.put()
     mail.send_mail(sender="Crypt Chat <*****@*****.**>", to=senderEmail, subject="New Crypt Chat Avatar", body="""
     Hey!
     We see you chose a new Crypt Chat avatar picture!
     Looks good!
     Sincerely,
     The Crypt Chat Team
     """)
     self.redirect("/")
Exemplo n.º 5
0
 def get(self):
     user_email = user_help.get_user_email()
     if user_email:
         user_email = user_email.lower()
         q = CryptChatUser.query(CryptChatUser.email == user_email)
         entity = q.get()
     n = int(self.request.get('n'))
     e = int(self.request.get('e'))
     # store user's public key in NDB as Strings
     entity.n = str(n)
     entity.e = str(e)
     entity.put()
     server_e, server_n = crypto_helper.get_server_pubkey()
     self.response.write(str(server_e) + "." + str(server_n))
Exemplo n.º 6
0
 def get(self, room_name):
     user_email = user_help.get_user_email()
     q = CryptChatUser.query(CryptChatUser.email == user_email)
     entity = q.get()
     client_e = float(entity.e)
     client_n = float(entity.n)
     room = str(room_name)
     all_messages = message.get_messages(room, 50)
     o = dict()
     o["all"] = list()
     for mess in all_messages:
         mess.text = crypto_helper.encrypt(None, client_n, client_e, mess.text)
         o["all"].append(mess.to_json())
     output = json.dump(o, self.response.out)
Exemplo n.º 7
0
    def get(self):
        sender_email = user_help.get_user_email()
        if sender_email:
            sender_email = sender_email.lower();
            q = CryptChatUser.query(CryptChatUser.email == sender_email.lower())
            entity = q.get()
            if entity is None: #create new user for this email
                newuser = CryptChatUser()
                newuser.email = sender_email.lower()
                newuser.avatar = '0'
                newuser.put()
                time.sleep(5)

        template_params = {
            'send_url': '/',
            'user_email': sender_email,
            'login_url': users.create_login_url(),
            'logout_url': users.create_logout_url('/'),
            'user_nickname': user_help.get_user_nickname(),
            'is_user_authenticated': crypto_helper.is_user_authenticated(sender_email)
        }
        template_help.render_template(self, 'index.html', template_params)