Exemplo n.º 1
0
    def __request_password(self, new_user=False, old_password=False):
        """ Get from request.form the password values and check it """
        form = self.params
        password = form.get("password")
        password_new = form.get("password_new")
        password_check = form.get("password_check")

        if self.message:
            return False

        # Check that the password_new field is not empty
        if new_user and (password_new is None or len(password_new) == 0):
            self.message = g.users_msg("error_password_0")

        # Check that the password_check field is not empty
        elif new_user and (password_check is None or len(password_check) == 0):
            self.message = g.users_msg("error_password_2")

        elif password_new and len(password_new):
            self.user["password_new"] = password_new
            self.user["password_check"] = password_check

            # Check that the new password has between 6 and 30 characters.
            if not check.length(self.user["password_new"], 6, 30):
                self.message = g.users_msg("error_password_1")

            # Check that both passwords are the same
            elif self.user["password_new"] != self.user["password_check"]:
                self.message = g.users_msg("error_password_2")

        if old_password:
            # Verify that the old password matches the one entered.
            old_password = create_password(password)
            if self.user["password"] != old_password:
                self.message = g.users_msg("error_password_3")
Exemplo n.º 2
0
 def update(self):
     """ Update user values in the database """
     self.__request_account()
     self.__request_profile()
     self.__request_password()
     
     if 'file' in request.files and self.__upload_avatar():
         self.user['image'] = self.list_images
     
     if self.message is None:
         if len(request.form['password_new']):
             password_new = create_password(request.form['password_new'])
             self.user['password'] = password_new     
         
         # If is changed the username it's important
         # the old avatars directory in the new position
         if self.changed_username and len(self.user['image']):
             src = os.path.join(UP_AVATARS_FOLDER,self.changed_username[0])
             dst = os.path.join(UP_AVATARS_FOLDER,self.changed_username[1])
             shutil.move(src,dst)
         
         try:
             g.db.users.update({ '_id' : ObjectId(self.user['_id']) }, self.user)
             self.status = 'msg msg-success'
             self.message = g.users_msg('success_update_user')
         except PyMongoError:
             self.message = g.users_msg('error_mongo_update')
Exemplo n.º 3
0
 def change_password(self, check):
     """ """
     user = check_verify_remember(check)
     if user:
         g.chtml = ''
         chtml = captcha.displayhtml(
           public_key = "6Ldph8cSAAAAAGJK1OCZwgqWxctr6gS2FTCM3B1r",
           use_ssl = False,
           error = None)
         g.chtml = Markup(chtml)
         g.check = check
         if request.method == 'POST':
             valid = self.recaptcha()
             if valid:
                 new_password = request.form['new_password'] 
                 new_password_two = request.form['new_password_two'] 
                 if len(new_password) < 6:
                     message = g.users_msg('error_password_1')
                     status = 'msg msg-error'
                 elif new_password != new_password_two:
                     message = g.users_msg('error_password_2')
                     status = 'msg msg-error'
                 else:
                     g.db.users.update({"_id": user['_id']}, {"$set": { "password": create_password(new_password) } })
                     message = g.users_msg('success_update_password')
                     status = 'msg msg-success'
             else:
                 message = g.login_msg('captcha_error')
                 status = 'msg msg-error'
         return render_template('{}/change_password.html'.format(MODULE_DIR), **locals())
     else:
         message = g.login_msg('not_change_password')
         status = 'msg msg-error'
         return render_template('{}/verify.html'.format(MODULE_DIR), **locals())
Exemplo n.º 4
0
    def update(self):
        """ Update user values in the database """
        self.__request_account()
        self.__request_profile()
        self.__request_password()

        if 'file' in request.files and self.__upload_avatar():
            self.user['image'] = self.list_images

        if self.message is None:
            if len(request.form['password_new']):
                password_new = create_password(request.form['password_new'])
                self.user['password'] = password_new

            # If is changed the username it's important
            # the old avatars directory in the new position
            if self.changed_username and len(self.user['image']):
                src = os.path.join(UP_AVATARS_FOLDER, self.changed_username[0])
                dst = os.path.join(UP_AVATARS_FOLDER, self.changed_username[1])
                shutil.move(src, dst)

            try:
                g.db.users.update({'_id': ObjectId(self.user['_id'])},
                                  self.user)
                self.status = 'msg msg-success'
                self.message = g.users_msg('success_update_user')
            except PyMongoError:
                self.message = g.users_msg('error_mongo_update')
Exemplo n.º 5
0
 def __upload_avatar(self):
     """ Upload the avatar """
     self.image = request.files['file']
     
     if not self.message is None:
         return False
             
     if len(self.image.filename) > 3:
         up = Upload(self.user['username'], self.image)
         
         # ~
         if not up.allowed_file():
             self.message = g.users_msg('error_upload_1')
             
         # ~
         elif not up.check_aspect_ratio(1):
             self.message = g.users_msg('error_upload_2')
         
         # ~
         else:
             up.avatar_upload()
             self.list_images = up.names_list
             return True
             
     return False
Exemplo n.º 6
0
    def __upload_avatar(self):
        """ Upload the avatar """
        self.image = request.files['file']

        if not self.message is None:
            return False

        if len(self.image.filename) > 3:
            up = Upload(self.user['username'], self.image)

            # ~
            if not up.allowed_file():
                self.message = g.users_msg('error_upload_1')

            # ~
            elif not up.check_aspect_ratio(1):
                self.message = g.users_msg('error_upload_2')

            # ~
            else:
                up.avatar_upload()
                self.list_images = up.names_list
                return True

        return False
Exemplo n.º 7
0
 def __request_profile(self):
     """ Get from request.form the profile values and check it """
     form                     = request.form
     self.user['name']        = form['name']
     self.user['description'] = form['description']
     self.user['location']    = form['location']
     self.user['web']         = form['web']
     
     if not self.message is None:
         return False
     
     # Check that the name field is not empty
     if not len(self.user['name']):
         self.message = g.users_msg('error_profile_1')
     
     # Check that the name has between 2 and 60 characters.
     elif not check.length(self.user['name'], 2, 60):
         self.message = g.users_msg('error_profile_2')
     
     # Check that the format of the full name is correct
     # and verify that its field is not empty
     elif not check.full_name(self.user['name']) or not len(self.user['name']):
         self.message = g.users_msg('error_profile_3')
         
     # Check that the format of the web url is correct
     # and verify that its field is not empty
     elif not check.url(self.user['web']) and len(self.user['web']):
         self.message = g.users_msg('error_profile_4')
Exemplo n.º 8
0
 def __request_password(self, new_user=False):
     """ Get from request.form the password values and check it """
     if not self.message is None:
         return False
     
     # Check that the password_new field is not empty
     if not len(request.form['password_new']) and new_user:
         self.message = g.users_msg('error_password_0')
     
     if len(request.form['password_new']):
         self.user['password_new'] = request.form['password_new']
         self.user['password_check'] = request.form['password_check']
                
         # Check that the new password has between 6 and 30 characters.
         if not check.length(self.user['password_new'], 6, 30):
             self.message = g.users_msg('error_password_1')	
         
         # Check that both passwords are the same
         elif self.user['password_new'] != self.user['password_check']:
             self.message = g.users_msg('error_password_2')
         
     if 'password' in request.form:
         # Verify that the old password matches the one entered.
         old_password = create_password(request.form['password'])
         if self.user['password'] != old_password: 
             self.message = g.users_msg('error_password_3')
Exemplo n.º 9
0
    def __request_profile(self):
        """ Get from request.form the profile values and check it """
        form = self.params
        self.user["name"] = form["name"].strip()
        self.user["description"] = form["description"].strip()
        self.user["location"] = form["location"]
        self.user["web"] = form["web"].strip()

        if self.message:
            return False

        # Check that the name field is not empty
        if not len(self.user["name"]):
            self.message = g.users_msg("error_profile_1")

        # Check that the name has between 2 and 60 characters.
        elif not check.length(self.user["name"], 2, 60):
            self.message = g.users_msg("error_profile_2")

        # Check that the format of the full name is correct
        # and verify that its field is not empty
        elif not check.full_name(self.user["name"]) or not len(self.user["name"]):
            self.message = g.users_msg("error_profile_3")

        # Check that the format of the web url is correct
        # and verify that its field is not empty
        elif not check.url(self.user["web"]) and len(self.user["web"]):
            self.message = g.users_msg("error_profile_4")
Exemplo n.º 10
0
    def __request_password(self, new_user=False, old_password=False):
        """ Get from request.form the password values and check it """
        form = self.params
        password = form.get('password')
        password_new = form.get('password_new')
        password_check = form.get('password_check')

        if self.message:
            return False

        # Check that the password_new field is not empty
        if new_user and (password_new is None or len(password_new) == 0):
            self.message = g.users_msg('error_password_0')

        # Check that the password_check field is not empty
        elif new_user and (password_check is None or len(password_check) == 0):
            self.message = g.users_msg('error_password_2')

        elif password_new and len(password_new):
            self.user['password_new'] = password_new
            self.user['password_check'] = password_check

            # Check that the new password has between 6 and 30 characters.
            if not check.length(self.user['password_new'], 6, 30):
                self.message = g.users_msg('error_password_1')

            # Check that both passwords are the same
            elif self.user['password_new'] != self.user['password_check']:
                self.message = g.users_msg('error_password_2')

        if old_password:
            # Verify that the old password matches the one entered.
            old_password = create_password(password)
            if self.user['password'] != old_password:
                self.message = g.users_msg('error_password_3')
Exemplo n.º 11
0
    def __request_profile(self):
        """ Get from request.form the profile values and check it """
        form = self.params
        self.user['name'] = form['name'].strip()
        self.user['description'] = form['description'].strip()
        self.user['location'] = form['location']
        self.user['web'] = form['web'].strip()

        if self.message:
            return False

        # Check that the name field is not empty
        if not len(self.user['name']):
            self.message = g.users_msg('error_profile_1')

        # Check that the name has between 2 and 60 characters.
        elif not check.length(self.user['name'], 2, 60):
            self.message = g.users_msg('error_profile_2')

        # Check that the format of the full name is correct
        # and verify that its field is not empty
        elif not check.full_name(self.user['name']) or not len(
                self.user['name']):
            self.message = g.users_msg('error_profile_3')

        # Check that the format of the web url is correct
        # and verify that its field is not empty
        elif not check.url(self.user['web']) and len(self.user['web']):
            self.message = g.users_msg('error_profile_4')
Exemplo n.º 12
0
    def __request_password(self, new_user=False, old_password=False):
        """ Get from request.form the password values and check it """
        form = self.params

        if self.message:
            return False

        # Check that the password_new field is not empty
        if new_user and (not "password_new" in form
                         or not len(form['password_new'])):
            self.message = g.users_msg('error_password_0')

        # Check that the password_check field is not empty
        elif new_user and (not "password_check" in form
                           or not len(form['password_check'])):
            self.message = g.users_msg('error_password_2')

        elif "password_new" in form and len(form['password_new']):
            self.user['password_new'] = form['password_new']
            self.user['password_check'] = form['password_check']

            # Check that the new password has between 6 and 30 characters.
            if not check.length(self.user['password_new'], 6, 30):
                self.message = g.users_msg('error_password_1')

            # Check that both passwords are the same
            elif self.user['password_new'] != self.user['password_check']:
                self.message = g.users_msg('error_password_2')

        if old_password:
            # Verify that the old password matches the one entered.
            old_password = create_password(form['password'])
            if self.user['password'] != old_password:
                self.message = g.users_msg('error_password_3')
Exemplo n.º 13
0
 def update(self):
     """ Update user values in the database """
     form = self.params
     self.__request_account()
     self.__request_profile()
     self.__request_password()
     
     if self.changed_email:
         self.user['email'] = self.user['new_email']
     
     if 'image_uploaded' in form and len(form['image_uploaded']):
         if self.__upload_avatar():
             self.user['image'] = self.list_images
     
     if not self.message:
         if len(form['password_new']):
             self.user['password'] = create_password(form['password_new'])
             del(self.user['password_new'])
             del(self.user['password_check'])
         
         if 'image_tmp' in self.user:
             del(self.user['image_tmp'])
         
         try:
             g.db.users.update({ '_id' : ObjectId(self.user['_id']) }, self.user)
             self.success = True
             self.message = g.users_msg('success_update_user')
         except PyMongoError, e:
             print 'Error caught in users.update : {0}'.format(e)
             self.message = g.users_msg('error_mongo_update')
Exemplo n.º 14
0
    def __request_password(self, new_user=False, old_password=False):
        """ Get from request.form the password values and check it """
        form = self.params

        if self.message:
            return False
        
        # Check that the password_new field is not empty
        if new_user and (not "password_new" in form or not len(form['password_new'])):
            self.message = g.users_msg('error_password_0')

        # Check that the password_check field is not empty
        elif new_user and (not "password_check" in form or not len(form['password_check'])):
            self.message = g.users_msg('error_password_2')
        
        elif "password_new" in form and len(form['password_new']):
            self.user['password_new'] = form['password_new']
            self.user['password_check'] = form['password_check']
            
            # Check that the new password has between 6 and 30 characters.
            if not check.length(self.user['password_new'], 6, 30):
                self.message = g.users_msg('error_password_1')  
            
            # Check that both passwords are the same
            elif self.user['password_new'] != self.user['password_check']:
                self.message = g.users_msg('error_password_2')

        if old_password:
            # Verify that the old password matches the one entered.
            old_password = create_password(form['password'])
            if self.user['password'] != old_password: 
                self.message = g.users_msg('error_password_3')
Exemplo n.º 15
0
    def update(self):
        """ Update user values in the database """
        form = self.params
        self.__request_account()
        self.__request_profile()
        self.__request_password()

        if self.changed_email:
            self.user['email'] = self.user['new_email']

        if 'image_uploaded' in form and len(form['image_uploaded']):
            if self.__upload_avatar():
                self.user['image'] = self.list_images

        if not self.message:
            if len(form['password_new']):
                self.user['password'] = create_password(form['password_new'])
                del (self.user['password_new'])
                del (self.user['password_check'])

            if 'image_tmp' in self.user:
                del (self.user['image_tmp'])

            try:
                g.db.users.update({'_id': ObjectId(self.user['_id'])},
                                  self.user)
                self.success = True
                self.message = g.users_msg('success_update_user')
            except PyMongoError, e:
                print 'Error caught in users.update : {0}'.format(e)
                self.message = g.users_msg('error_mongo_update')
Exemplo n.º 16
0
    def __request_password(self, new_user=False):
        """ Get from request.form the password values and check it """
        if not self.message is None:
            return False

        # Check that the password_new field is not empty
        if not len(request.form['password_new']) and new_user:
            self.message = g.users_msg('error_password_0')

        if len(request.form['password_new']):
            self.user['password_new'] = request.form['password_new']
            self.user['password_check'] = request.form['password_check']

            # Check that the new password has between 6 and 30 characters.
            if not check.length(self.user['password_new'], 6, 30):
                self.message = g.users_msg('error_password_1')

            # Check that both passwords are the same
            elif self.user['password_new'] != self.user['password_check']:
                self.message = g.users_msg('error_password_2')

        if 'password' in request.form:
            # Verify that the old password matches the one entered.
            old_password = create_password(request.form['password'])
            if self.user['password'] != old_password:
                self.message = g.users_msg('error_password_3')
Exemplo n.º 17
0
 def update_password(self):
     """ Update user values in the database """
     self.__request_password()
     if self.message is None:
         password_new = create_password(request.form['password_new'])
         self.user['password'] = password_new     
         
         try:
             g.db.users.update({ '_id' : ObjectId(self.user['_id']) }, self.user)
             self.status = 'msg msg-success'
             self.message = g.users_msg('success_update_password')
         except PyMongoError:
             self.message = g.users_msg('account_error_1')
Exemplo n.º 18
0
    def update_password(self):
        """ Update user values in the database """
        self.__request_password()
        if self.message is None:
            password_new = create_password(request.form['password_new'])
            self.user['password'] = password_new

            try:
                g.db.users.update({'_id': ObjectId(self.user['_id'])},
                                  self.user)
                self.status = 'msg msg-success'
                self.message = g.users_msg('success_update_password')
            except PyMongoError:
                self.message = g.users_msg('account_error_1')
Exemplo n.º 19
0
 def update_profile(self):
     """ Update user values in the database """
     self.__request_profile()
     
     if 'file' in request.files and self.__upload_avatar():
         self.user['image'] = self.list_images
     
     if self.message is None:
         try:
             g.db.users.update({ '_id' : ObjectId(self.user['_id']) }, self.user)
             self.status = 'msg msg-success'
             self.message = g.users_msg('success_update_profile')
         except PyMongoError:
             self.message = g.users_msg('account_error_1')
Exemplo n.º 20
0
    def update_profile(self):
        """ Update user values in the database """
        self.__request_profile()

        if 'file' in request.files and self.__upload_avatar():
            self.user['image'] = self.list_images

        if self.message is None:
            try:
                g.db.users.update({'_id': ObjectId(self.user['_id'])},
                                  self.user)
                self.status = 'msg msg-success'
                self.message = g.users_msg('success_update_profile')
            except PyMongoError:
                self.message = g.users_msg('account_error_1')
Exemplo n.º 21
0
    def new(self):
        """ Insert new user in the database """
        form = self.params
        self.__request_account()
        self.__request_profile()
        self.__request_password(new_user=True)

        if self.changed_email:
            self.user['email'] = self.user['new_email']

        if self.message is None:
            self.user['password'] = create_password(form['password_new'])
            del(self.user['password_new'])
            del(self.user['password_check'])
            self.user['status'] = ACTIVATED

            if 'image_tmp' in self.user:
                del(self.user['image_tmp'])

            self.user['_id'] = model.users.create(self.user)
            if len(form.get('image_uploaded', '')) > 0:
                if self.__upload_avatar():
                    self.user['image'] = self.list_images
                    model.users.update(user_id=self.user['_id'],
                                       user=self.user)

            self.success = True
            self.message = g.users_msg('success_new_user')

        return False
Exemplo n.º 22
0
    def update(self):
        """ Update user values in the database """
        form = self.params
        self.__request_account()
        self.__request_profile()
        self.__request_password()

        if self.changed_email:
            self.user['email'] = self.user['new_email']

        if len(form.get('image_uploaded', '')) > 0:
            if self.__upload_avatar():
                self.user['image'] = self.list_images

        if self.message is None:
            if len(form['password_new']):
                self.user['password'] = create_password(form['password_new'])
                del(self.user['password_new'])
                del(self.user['password_check'])

            if 'image_tmp' in self.user:
                del(self.user['image_tmp'])

            model.users.update(user_id=self.user['_id'],
                               user=self.user)
            self.success = True
            self.message = g.users_msg('success_update_user')

        self.user['password_new'] = ""
        self.user['password_check'] = ""
Exemplo n.º 23
0
 def update_password(self):
     """ Update user values in the database """
     form = self.params
     self.__request_password(True, True)
     if not self.message:
         self.user['password'] = create_password(form['password_new'])
         del(self.user['password_new'])
         del(self.user['password_check'])
         
         try:
             g.db.users.update({ '_id' : ObjectId(self.user['_id']) }, self.user)
             self.success = True
             self.message = g.users_msg('success_update_password')
         except PyMongoError, e:
             print 'Error caught in users.update_password : {0}'.format(e)
             self.message = g.users_msg('account_error_1')
Exemplo n.º 24
0
 def update_profile(self):
     """ Update user values in the database """
     form = self.params
     self.__request_profile()
     
     if 'image_uploaded' in form and self.__upload_avatar():
         self.user['image'] = self.list_images
     
     if self.message is None:
         try:
             g.db.users.update({ '_id' : ObjectId(self.user['_id']) }, self.user)
             self.success = True
             self.message = g.users_msg('success_update_profile')
         except PyMongoError, e:
             print 'Error caught in users.update_profile : {0}'.format(e)
             self.message = g.users_msg('account_error_1')
Exemplo n.º 25
0
    def update(self):
        """ Update user values in the database """
        form = self.params
        self.__request_account()
        self.__request_profile()
        self.__request_password()

        if self.changed_email:
            self.user['email'] = self.user['new_email']

        if len(form.get('image_uploaded', '')) > 0:
            if self.__upload_avatar():
                self.user['image'] = self.list_images

        if self.message is None:
            if len(form['password_new']):
                self.user['password'] = create_password(form['password_new'])
                del (self.user['password_new'])
                del (self.user['password_check'])

            if 'image_tmp' in self.user:
                del (self.user['image_tmp'])

            model.users.update(user_id=self.user['_id'], user=self.user)
            self.success = True
            self.message = g.users_msg('success_update_user')

        self.user['password_new'] = ""
        self.user['password_check'] = ""
Exemplo n.º 26
0
    def update(self):
        """ Update user values in the database """
        form = self.params
        self.__request_account()
        self.__request_profile()
        self.__request_password()

        if self.changed_email:
            self.user["email"] = self.user["new_email"]

        if len(form.get("image_uploaded", "")) > 0:
            if self.__upload_avatar():
                self.user["image"] = self.list_images

        if self.message is None:
            if len(form["password_new"]):
                self.user["password"] = create_password(form["password_new"])
                del (self.user["password_new"])
                del (self.user["password_check"])

            if "image_tmp" in self.user:
                del (self.user["image_tmp"])

            model.users.update(user_id=self.user["_id"], user=self.user)
            self.success = True
            self.message = g.users_msg("success_update_user")

        self.user["password_new"] = ""
        self.user["password_check"] = ""
Exemplo n.º 27
0
    def new(self):
        """ Insert new user in the database """
        form = self.params
        self.__request_account()
        self.__request_profile()
        self.__request_password(new_user=True)

        if self.changed_email:
            self.user["email"] = self.user["new_email"]

        if self.message is None:
            self.user["password"] = create_password(form["password_new"])
            del (self.user["password_new"])
            del (self.user["password_check"])
            self.user["status"] = ACTIVATED

            if "image_tmp" in self.user:
                del (self.user["image_tmp"])

            self.user["_id"] = model.users.create(self.user)
            if len(form.get("image_uploaded", "")) > 0:
                if self.__upload_avatar():
                    self.user["image"] = self.list_images
                    model.users.update(user_id=self.user["_id"], user=self.user)

            self.success = True
            self.message = g.users_msg("success_new_user")

        return False
Exemplo n.º 28
0
    def new(self):
        """ Insert new user in the database """
        form = self.params
        self.__request_account()
        self.__request_profile()
        self.__request_password(new_user=True)

        if self.changed_email:
            self.user['email'] = self.user['new_email']

        if self.message is None:
            self.user['password'] = create_password(form['password_new'])
            del (self.user['password_new'])
            del (self.user['password_check'])
            self.user['status'] = ACTIVATED

            if 'image_tmp' in self.user:
                del (self.user['image_tmp'])

            self.user['_id'] = model.users.create(self.user)
            if len(form.get('image_uploaded', '')) > 0:
                if self.__upload_avatar():
                    self.user['image'] = self.list_images
                    model.users.update(user_id=self.user['_id'],
                                       user=self.user)

            self.success = True
            self.message = g.users_msg('success_new_user')

        return False
Exemplo n.º 29
0
 def update_account(self):
     """ Update user values in the database """
     self.__request_account(True)
     
     if not self.message and self.changed_email:
         response = self.__check_new_email()
         if response['error']:
             self.message = g.users_msg('account_error_email_1')
     
     if not self.message:
         try:
             g.db.users.update({ '_id' : ObjectId(self.user['_id']) }, self.user)
             self.success = True
             self.message = g.users_msg('success_update_account')
         except PyMongoError, e:
             print 'Error caught in users.update_account : {0}'.format(e)
             self.message = g.users_msg('account_error_1')
Exemplo n.º 30
0
    def update_account(self):
        """ Update user values in the database """
        self.__request_account(True)

        if self.message is None and self.changed_email:
            response = _check_new_email(user=self.user)
            if not response['success']:
                self.message = g.users_msg('account_error_email_1')
            else:
                model.users.update(user_id=self.user['_id'], user=self.user)
                self.success = True
                self.message = g.users_msg('success_update_email')

        if self.message is None:
            model.users.update(user_id=self.user['_id'], user=self.user)
            self.success = True
            self.message = g.users_msg('success_update_account')
Exemplo n.º 31
0
    def update_profile(self):
        """ Update user values in the database """
        form = self.params
        self.__request_profile()

        if 'image_uploaded' in form and self.__upload_avatar():
            self.user['image'] = self.list_images

        if self.message is None:
            try:
                g.db.users.update({'_id': ObjectId(self.user['_id'])},
                                  self.user)
                self.success = True
                self.message = g.users_msg('success_update_profile')
            except PyMongoError, e:
                print 'Error caught in users.update_profile : {0}'.format(e)
                self.message = g.users_msg('account_error_1')
Exemplo n.º 32
0
    def update_password(self):
        """ Update user values in the database """
        form = self.params
        self.__request_password(True, True)
        if not self.message:
            self.user['password'] = create_password(form['password_new'])
            del (self.user['password_new'])
            del (self.user['password_check'])

            try:
                g.db.users.update({'_id': ObjectId(self.user['_id'])},
                                  self.user)
                self.success = True
                self.message = g.users_msg('success_update_password')
            except PyMongoError, e:
                print 'Error caught in users.update_password : {0}'.format(e)
                self.message = g.users_msg('account_error_1')
Exemplo n.º 33
0
    def update_account(self):
        """ Update user values in the database """
        self.__request_account(True)

        if self.message is None and self.changed_email:
            response = _check_new_email(user=self.user)
            if not response["success"]:
                self.message = g.users_msg("account_error_email_1")
            else:
                model.users.update(user_id=self.user["_id"], user=self.user)
                self.success = True
                self.message = g.users_msg("success_update_email")

        if self.message is None:
            model.users.update(user_id=self.user["_id"], user=self.user)
            self.success = True
            self.message = g.users_msg("success_update_account")
Exemplo n.º 34
0
 def update_account(self):
     """ Update user values in the database """
     self.__request_account(True)
     
     if self.message is None:
         # If is changed the username it's important
         # the old avatars directory in the new position
         if self.changed_username and len(self.user['image']):
             src = os.path.join(UP_AVATARS_FOLDER,self.changed_username[0])
             dst = os.path.join(UP_AVATARS_FOLDER,self.changed_username[1])
             shutil.move(src,dst)
         
         try:
             g.db.users.update({ '_id' : ObjectId(self.user['_id']) }, self.user)
             self.status = 'msg msg-success'
             self.message = g.users_msg('success_update_account')
         except PyMongoError:
             self.message = g.users_msg('account_error_1')
Exemplo n.º 35
0
    def update_account(self):
        """ Update user values in the database """
        self.__request_account(True)

        if not self.message and self.changed_email:
            response = self.__check_new_email()
            if response['error']:
                self.message = g.users_msg('account_error_email_1')

        if not self.message:
            try:
                g.db.users.update({'_id': ObjectId(self.user['_id'])},
                                  self.user)
                self.success = True
                self.message = g.users_msg('success_update_account')
            except PyMongoError, e:
                print 'Error caught in users.update_account : {0}'.format(e)
                self.message = g.users_msg('account_error_1')
Exemplo n.º 36
0
    def update_account(self):
        """ Update user values in the database """
        self.__request_account(True)

        if self.message is None:
            # If is changed the username it's important
            # the old avatars directory in the new position
            if self.changed_username and len(self.user['image']):
                src = os.path.join(UP_AVATARS_FOLDER, self.changed_username[0])
                dst = os.path.join(UP_AVATARS_FOLDER, self.changed_username[1])
                shutil.move(src, dst)

            try:
                g.db.users.update({'_id': ObjectId(self.user['_id'])},
                                  self.user)
                self.status = 'msg msg-success'
                self.message = g.users_msg('success_update_account')
            except PyMongoError:
                self.message = g.users_msg('account_error_1')
Exemplo n.º 37
0
    def update_profile(self):
        """ Update user values in the database """
        form = self.params
        self.__request_profile()

        if form.get('image_uploaded') and self.__upload_avatar():
            self.user['image'] = self.list_images

        if self.user.get('image_tmp'):
            del (self.user['image_tmp'])

        if self.message is None:
            model.users.update(user_id=self.user['_id'], user=self.user)
            self.success = True
            self.message = g.users_msg('success_update_profile')
Exemplo n.º 38
0
    def update_profile(self):
        """ Update user values in the database """
        form = self.params
        self.__request_profile()

        if form.get("image_uploaded") and self.__upload_avatar():
            self.user["image"] = self.list_images

        if self.user.get("image_tmp"):
            del (self.user["image_tmp"])

        if self.message is None:
            model.users.update(user_id=self.user["_id"], user=self.user)
            self.success = True
            self.message = g.users_msg("success_update_profile")
Exemplo n.º 39
0
    def update_profile(self):
        """ Update user values in the database """
        form = self.params
        self.__request_profile()

        if form.get('image_uploaded') and self.__upload_avatar():
            self.user['image'] = self.list_images

        if self.user.get('image_tmp'):
            del(self.user['image_tmp'])

        if self.message is None:
            model.users.update(user_id=self.user['_id'],
                               user = self.user)
            self.success = True
            self.message = g.users_msg('success_update_profile')
Exemplo n.º 40
0
 def new(self):
     """ Insert new user in the database """
     self.__request_account()
     self.__request_profile()
     self.__request_password(True)
     
     if self.message is None:
         password_new = create_password(request.form['password_new'])
         self.user['image'] = ''
         self.user['password'] = password_new
         try:
             g.db.users.insert(self.user)
             return True
         except PyMongoError:
             self.message = g.users_msg('error_mongo_new')
     
     return False
Exemplo n.º 41
0
    def update_password(self):
        """ Update user values in the database """
        form = self.params
        old_password = self.user.get('password', False)
        self.__request_password(old_password=old_password)
        if self.message is None:
            self.user['password'] = create_password(form['password_new'])
            del (self.user['password_new'])
            del (self.user['password_check'])

            model.users.update(user_id=self.user['_id'], user=self.user)
            self.success = True
            self.message = g.users_msg('success_update_password')

        self.user['password'] = ""
        self.user['password_new'] = ""
        self.user['password_check'] = ""
Exemplo n.º 42
0
    def __upload_avatar(self):
        """ Upload the avatar """
        form = self.params
        self.user['image_tmp'] = form['image_uploaded']

        if self.message or not self.user['image_tmp']:
            return False

        file_name = os.path.join(UP_AVATARS_TMP_FOLDER, self.user['image_tmp'])
        if os.path.exists(file_name):
            with open(file_name) as image:
                up = UploadAvatar()
                up.upload(image=image, user=self.user)
                self.list_images = up.names_list
                return True
        self.message = g.users_msg('error_upload_2')
        return False
Exemplo n.º 43
0
    def new(self):
        """ Insert new user in the database """
        self.__request_account()
        self.__request_profile()
        self.__request_password(True)

        if self.message is None:
            password_new = create_password(request.form['password_new'])
            self.user['image'] = ''
            self.user['password'] = password_new
            try:
                g.db.users.insert(self.user)
                return True
            except PyMongoError:
                self.message = g.users_msg('error_mongo_new')

        return False
Exemplo n.º 44
0
def upload_avatar(name=None):
    """
    """
    extension = get_extension(name)
    up = UploadAvatar()
    path_image = up.ajax_upload(UP_AVATARS_TMP_FOLDER, extension)
    if up.allowed_file() == False:
        success = False
        message = g.users_msg("error_upload_1")
    else:
        up.thumb(AVATAR_IMAGE_SIZE["large"], os.path.join(UP_AVATARS_TMP_FOLDER, path_image))
        if path_image:
            success = True
            message = path_image
    if success:
        return dict(success=True, message=message)
    return dict(success=False, errors=[{"message": message}])
Exemplo n.º 45
0
    def update_password(self):
        """ Update user values in the database """
        form = self.params
        old_password = self.user.get("password", False)
        self.__request_password(old_password=old_password)
        if self.message is None:
            self.user["password"] = create_password(form["password_new"])
            del (self.user["password_new"])
            del (self.user["password_check"])

            model.users.update(user_id=self.user["_id"], user=self.user)
            self.success = True
            self.message = g.users_msg("success_update_password")

        self.user["password"] = ""
        self.user["password_new"] = ""
        self.user["password_check"] = ""
Exemplo n.º 46
0
    def __upload_avatar(self):
        """ Upload the avatar """
        form = self.params
        self.user["image_tmp"] = form["image_uploaded"]

        if self.message or not self.user["image_tmp"]:
            return False

        file_name = os.path.join(UP_AVATARS_TMP_FOLDER, self.user["image_tmp"])
        if os.path.exists(file_name):
            with open(file_name) as image:
                up = UploadAvatar()
                up.upload(image=image, user=self.user)
                self.list_images = up.names_list
                return True
        self.message = g.users_msg("error_upload_2")
        return False
Exemplo n.º 47
0
    def update_password(self):
        """ Update user values in the database """
        form = self.params
        old_password = self.user.get('password', False)
        self.__request_password(old_password=old_password)
        if self.message is None:
            self.user['password'] = create_password(form['password_new'])
            del(self.user['password_new'])
            del(self.user['password_check'])

            model.users.update(user_id=self.user['_id'],
                               user = self.user)
            self.success = True
            self.message = g.users_msg('success_update_password')

        self.user['password'] = ""
        self.user['password_new'] = ""
        self.user['password_check'] = ""
Exemplo n.º 48
0
def upload_avatar(name=None):
    """
    """
    extension = get_extension(name)
    up = UploadAvatar()
    path_image = up.ajax_upload(UP_AVATARS_TMP_FOLDER, extension)
    if up.allowed_file() == False:
        success = False
        message = g.users_msg('error_upload_1')
    else:
        up.thumb(AVATAR_IMAGE_SIZE['large'],
                 os.path.join(UP_AVATARS_TMP_FOLDER, path_image))
        if path_image:
            success = True
            message = path_image
    if success:
        return dict(success=True, message=message)
    return dict(success=False, errors=[{"message": message}])
Exemplo n.º 49
0
 def __upload_avatar(self):
     """ Upload the avatar """
     form = self.params
     self.user['image_tmp'] = form['image_uploaded']
     
     if self.message or not self.user['image_tmp']:
         return False
     
     file_name = os.path.join(UP_AVATARS_TMP_FOLDER, self.user['image_tmp'])
     if os.path.exists(file_name):
         with open(file_name) as image:
             up = Upload(self.user['username'], image)
             up.avatar_upload(self.user['_id'])
         
         self.list_images = up.names_list
         return True
     
     self.message = g.users_msg('error_upload_2')
     return False
Exemplo n.º 50
0
def upload_avatar():
    """ """

    name = secure_filename(request.headers.get('X-File-Name'))
    extension = name.rsplit('.', 1)[1].lower()

    up = Upload()
    path_image = up.ajax_upload(UP_AVATARS_TMP_FOLDER, extension)

    if not up.allowed_file():
        success = False
        message = g.users_msg('error_upload_1')
    else:
        up.thumb((128, 128), os.path.join(UP_AVATARS_TMP_FOLDER, path_image))
        if path_image != 'error':
            success = True
            message = path_image

    data = {"success": success, "message": message}

    return jsonify(data)
Exemplo n.º 51
0
def upload_avatar():
    """ """

    name = secure_filename(request.headers.get('X-File-Name'))
    extension = name.rsplit('.', 1)[1].lower()
    
    up = Upload()
    path_image = up.ajax_upload(UP_AVATARS_TMP_FOLDER, extension)
    
    if not up.allowed_file():
        success = False
        message = g.users_msg('error_upload_1')
    else:
        up.thumb((128, 128), os.path.join(UP_AVATARS_TMP_FOLDER, path_image))
        if path_image != 'error':
            success = True
            message = path_image

    data = {
        "success": success,
        "message": message
    }

    return jsonify(data)
Exemplo n.º 52
0
    def __request_account(self, settings=None):
        """ Get from request.form the account values and check it """
        form = self.params
        old_username = self.user["username"]
        self.user["username"] = form["username"]
        old_email = self.user["email"]
        new_email = str.lower(str(form["email"]))
        self.user["lan"] = form["lan"]
        self.user["time_zone"] = form["time_zone"]

        if "status" in form:
            self.user["status"] = int(form["status"])

        if not settings and g.my["rank"] == 10:
            if form["rank"] in map(str, range(10, 90, 10)):
                self.user["rank"] = int(form["rank"])

        # Check that the username field is not empty
        if not len(self.user["username"]):
            self.message = g.users_msg("error_account_1")

        # If the username is changed
        elif old_username != self.user["username"]:
            # It's important to change directory avatars
            # Changed username from old_username to new_username
            new_username = unicode(self.user["username"]).lower()
            old_username = unicode(old_username).lower()

            # Check the username is available and if is different from old username
            if new_username != old_username:
                try:
                    regx = re.compile("^" + new_username + "$", re.IGNORECASE)
                    available_username = g.db.users.find_one({"username": regx})
                except:
                    available_username = "******"
            else:
                available_username = None

            # Check that the username has between 2 and 20 characters
            if not check.length(self.user["username"], 2, 20):
                self.message = g.users_msg("error_account_2")

            # Verify that the format of the username is correct
            elif not check.username(self.user["username"]):
                self.message = g.users_msg("error_account_3")

            # Raises an error message if username is not available.
            elif not available_username is None:
                self.message = g.users_msg("error_account_5")

        # Check that the email field is not empty
        if not self.message and not len(form["email"]):
            self.message = g.users_msg("error_account_6")

        # If the email is changed
        elif not self.message and old_email != new_email:
            self.user["new_email"] = new_email
            available_email = model.users.find(email=self.user["new_email"], my_rank=10, only_one=True)

            # Verify that the format of the email is correct
            if not check.email(self.user["new_email"]):
                self.message = g.users_msg("error_account_7")

            # Raises an error message if email is not available.
            elif available_email:
                self.message = g.users_msg("error_account_8")

            self.changed_email = True

        # Check that the language field is checked
        if not self.message and not self.user["lan"] in LIST_LANGUAGES:
            self.message = g.users_msg("error_account_9")

        # Check that the timezone field is checked
        if not self.message and not len(self.user["time_zone"]):
            self.message = g.users_msg("error_account_10")
Exemplo n.º 53
0
    def __request_account(self, settings=None):
        """ Get from request.form the account values and check it """
        form = request.form
        old_username = self.user['username']
        old_email = self.user['email']
        self.user['username'] = form['username']
        self.user['email'] = str.lower(str(form['email']))
        self.user['lan'] = form['language']
        self.user['time_zone'] = form['time_zone']

        if settings is None:
            self.user['rank'] = int(form['rank'])

        # Check that the username field is not empty
        if not len(form['username']):
            self.message = g.users_msg('error_account_1')

        # If the username is changed
        elif old_username != self.user['username']:
            # It's important to change directory avatars
            # Changed username from old_username to new_username
            new_username = str.lower(str(self.user['username']))
            old_username = str.lower(str(old_username))
            self.changed_username = (old_username, new_username)

            # Check the username is available and if is different from old username
            if new_username != old_username:
                try:
                    regx = re.compile('^' + new_username + '$', re.IGNORECASE)
                    available_username = g.db.users.find_one(
                        {"username": regx})
                except:
                    available_username = '******'
            else:
                available_username = None

            # Check that the username has between 2 and 20 characters
            if not check.length(self.user['username'], 2, 20):
                self.message = g.users_msg('error_account_2')

            # Verify that the format of the username is correct
            elif not check.username(self.user['username']):
                self.message = g.users_msg('error_account_3')

            # Check that the username is not among those prohibited.
            elif self.user['username'] in PROHIBITED_NAME_LIST:
                self.message = g.users_msg('error_account_4')

            # Raises an error message if username is not available.
            elif not available_username is None:
                self.message = g.users_msg('error_account_5')

        # Check that the email field is not empty
        if not len(form['email']):
            self.message = g.users_msg('error_account_6')

        # If the email is changed
        elif old_email != self.user['email']:
            available_email = g.db.users.find_one(
                {"email": self.user['email']})

            # Verify that the format of the email is correct
            if not check.email(self.user['email']):
                self.message = g.users_msg('error_account_7')

            # Raises an error message if email is not available.
            elif not available_email is None:
                self.message = g.users_msg('error_account_8')
Exemplo n.º 54
0
    def __request_account(self, settings=None):
        """ Get from request.form the account values and check it """
        form = self.params
        old_username = self.user['username']
        self.user['username'] = form['username']
        old_email = self.user['email']
        new_email = str.lower(str(form['email']))
        self.user['lan'] = form['lan']
        self.user['time_zone'] = form['time_zone']

        if 'status' in form:
            self.user['status'] = int(form['status'])

        if not settings and g.my["rank"] == 10:
            if form['rank'] in map(str, range(10, 90, 10)):
                self.user['rank'] = int(form['rank'])

        # Check that the username field is not empty
        if not len(self.user['username']):
            self.message = g.users_msg('error_account_1')

        # If the username is changed
        elif old_username != self.user['username']:
            # It's important to change directory avatars
            # Changed username from old_username to new_username
            new_username = unicode(self.user['username']).lower()
            old_username = unicode(old_username).lower()

            # Check the username is available and if is different from old username
            if new_username != old_username:
                try:
                    regx = re.compile('^' + new_username + '$', re.IGNORECASE)
                    available_username = g.db.users.find_one(
                        {"username": regx})
                except:
                    available_username = '******'
            else:
                available_username = None

            # Check that the username has between 2 and 20 characters
            if not check.length(self.user['username'], 2, 20):
                self.message = g.users_msg('error_account_2')

            # Verify that the format of the username is correct
            elif not check.username(self.user['username']):
                self.message = g.users_msg('error_account_3')

            # Raises an error message if username is not available.
            elif not available_username is None:
                self.message = g.users_msg('error_account_5')

        # Check that the email field is not empty
        if not self.message and not len(form['email']):
            self.message = g.users_msg('error_account_6')

        # If the email is changed
        elif not self.message and old_email != new_email:
            self.user['new_email'] = new_email
            available_email = model.users.find(email=self.user['new_email'],
                                               my_rank=10,
                                               only_one=True)

            # Verify that the format of the email is correct
            if not check.email(self.user['new_email']):
                self.message = g.users_msg('error_account_7')

            # Raises an error message if email is not available.
            elif available_email:
                self.message = g.users_msg('error_account_8')

            self.changed_email = True

        # Check that the language field is checked
        if not self.message and not self.user['lan'] in LIST_LANGUAGES:
            self.message = g.users_msg('error_account_9')

        # Check that the timezone field is checked
        if not self.message and not len(self.user['time_zone']):
            self.message = g.users_msg('error_account_10')