Exemple #1
0
def passwordSendEmail(request, format=None):
    if request.method == 'PUT':
        data = JSONParser().parse(request)
        email = getPropertyByName('email', data.items())
        token = getPropertyByName('token', data.items())

        if correctForgotPasswordToken(email, token):
            TO = email
            tmpPassword = tokenGenerator()
            code = md5Encoding(tmpPassword)
            SUBJECT = "AliveTracker reset password message. (DO NOT REPLY)"
            FROM = "*****@*****.**"
            MESSAGE = """
            You requested to have your password reset, below is your new password.

                      Username:""" + TO + """
                      New Password: """ + tmpPassword + """

                      To login your new password, please go to
                      http://www.alivetracker.com
            Thanks,
            AliveTracker Team"""
            try:
                User.objects.filter(email=TO).update(password=code, entity_status=2)
            except:
                return responseJsonUtil(False, 'ERROR000', None)
            try:
                sendEmail(FROM, TO, SUBJECT, MESSAGE)
                return responseJsonUtil(True, None, None)
            except:
                return responseJsonUtil(False, 'ERROR002', None)
        else:
            return responseJsonUtil(False, 'ERROR100', None)
Exemple #2
0
def resetPassword(request, format=None):
    if request.method == 'PUT':
        data = JSONParser().parse(request)
        tmpEmail = getPropertyByName('email', data.items())
        tmpToken = getPropertyByName('token', data.items())
        tmpPassword = getPropertyByName('password', data.items())
        if correctForgotPasswordToken(tmpEmail, tmpToken):
            User.objects.filter(email=tmpEmail).update(password=tmpPassword)
            tmpUser = User.objects.get(email=tmpEmail)
            newSessionHandler(request, tmpUser);
            tmpSerializer = UserSerializer(tmpUser)
            return responseJsonUtil(True, None, tmpSerializer)
        else:
            return responseJsonUtil(False, 'ERROR104', None)