Example #1
0
 def get_user_object(cls, email=None, _id=None):
     """
     This method returns a user object by searching either through the email or the unique id
     :param email: The email of the user, None by default
     :param _id: The unique id of the user, None by default
     :return: returns a User object either by searching with email or _id
     """
     if email is not None:
         user_data = Database.find_user_email(email)
         user = cls(user_data['email'], user_data['password'],
                    user_data['name'], user_data['phone_no'],
                    user_data['gender'], user_data['dob'], user_data['_id'],
                    user_data['email_verified'],
                    user_data['current_address'],
                    user_data['permanent_address'], user_data['tel_no'],
                    user_data['nationality'], user_data['disability'],
                    user_data['source_awards'], user_data['photo_path'])
     else:
         user_data = Database.find_user_id(_id)
         user = cls(user_data['email'], user_data['password'],
                    user_data['name'], user_data['phone_no'],
                    user_data['gender'], user_data['dob'], user_data['_id'],
                    user_data['email_verified'],
                    user_data['current_address'],
                    user_data['permanent_address'], user_data['tel_no'],
                    user_data['nationality'], user_data['disability'],
                    user_data['source_awards'], user_data['photo_path'])
     return user
Example #2
0
 def save_to_database(self):
     Database.insert_user(self._id, self.email, self.password, self.name,
                          self.phone_no, self.gender, self.dob,
                          self.email_verified, self.current_address,
                          self.permanent_address, self.tel_no,
                          self.nationality, self.disability,
                          self.source_awards, self.photo_path)
Example #3
0
    def is_login_valid(email, password):
        """
        This method verifies that an email and password combo(as sent by the site forms) is valid or not.
        Checks that the email exists and the password associated with it is correct.
        :param email: The user's email
        :param password: A sha512 hashed password
        :return: True if valid, False otherwise
        """
        user_data = Database.find_user_email(
            email)  # password in sha512-> pbkdf2_sha512
        if user_data is None:
            # tell the user the email does not exists
            raise UserErrors.UserNotExistsError("This email does not exists.")
        if not Utils.check_hashed_password(password, user_data['password']):
            # tell the user that the password is incorrect
            raise UserErrors.IncorrectPasswordError("Your password was wrong.")
        if user_data['email_verified'] != 'yes':
            raise UserErrors.EmailNotVerfiedError(
                "Please verify your e-mail before accessing your dashboard.")

        return True
Example #4
0
    def register_user(email, password, name, phone_no, gender, dob):
        """
        This method registers a user to the database using the entered details.
        The password already comes in a sha512 hashed format
        :param email: Email entered by the user
        :param password: sha512 hashed password
        :return: True if registration is successful, an exception is raised otherwise

        """
        # user_data = Database.find_one(COLLECTION, {'email': email})
        user_data = Database.find_user_email(email)
        if user_data is not None:
            raise UserErrors.UserAlreadyRegisteredError(
                'This email is already registered with us.')
        if not Utils.email_is_valid(email):
            raise UserErrors.InvalidEmailError(
                'The email is not of a valid format')

        User(email, Utils.hash_password(password), name, phone_no, gender,
             dob).save_to_database()
        return True
    def email_alerts_form_2(reminder_number):
        """
        This sends an email alert to those whose form 2 is incomplete.
        :param mail: not to be touched. mail instance from app.py
        :param reminder_number: reminder_1 or reminder_2
        :return: nothing
        """
        volunteering_experience = VolunteeringExperience(None, None, None, None, None, None, None, None)

        id_list = volunteering_experience.get_all_saved()

        for each_id in id_list:
            email = Database.find_user_id(each_id)['email']
            msg = Message('Your phase 1 form is incomplete',
                          sender='*****@*****.**',
                          recipients=[email])
            msg.body = "Your phase 2 form is incomplete, please go to your dashboard to do the same.\n" \
                       "आपका चरण 2 फॉर्म अधूरा है, कृपया ऐसा करने के लिए अपने डैशबोर्ड पर जाएं।"
            MailSender.send_mail(msg)
            # mail.send(msg)
            VolunteeringExperience.update_reminder_status(each_id, reminder_number)
            time.sleep(8)
Example #6
0
 def save_form_1_details(_id, current_address, permanent_address, tel_no,
                         nationality, disability):
     Database.update_user_form(_id, current_address, permanent_address,
                               tel_no, nationality, disability)
Example #7
0
 def save_photo_path(self):
     Database.set_photo_path(self.photo_path, self._id)
Example #8
0
 def get_all_users():
     list = Database.get_all()
     return list
Example #9
0
 def change_password(password, _id):
     Database.change_password(password, _id)
Example #10
0
 def save_email_verified_status(self):
     Database.verify_user(self.email)
Example #11
0
 def update_database(self):
     Database.update_user(self._id, self.email, self.name, self.phone_no,
                          self.gender, self.dob, self.current_address,
                          self.permanent_address, self.tel_no,
                          self.nationality, self.disability,
                          self.source_awards, self.photo_path)