Example #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)
Example #2
0
def forgotPassword(request, format=None):
    if request.method == 'PUT':
        data = JSONParser().parse(request)
        TO = getPropertyByName('email', data.items())
        if emailExists(TO):
            code = md5Encoding(tokenGenerator())
            SUBJECT = "AliveTracker forgot password instructions. (DO NOT REPLY)"
            FROM = "*****@*****.**"
            MESSAGE = """
            Hey, we heard you lost your AliveTracker password.
            Use the following link to reset your password:

                     http://www.alivetracker.com/#resetPasswordPage?email=""" + TO + """&token=""" + code + """

            Ignore this email if you haven't experienced any password trouble.

            Thanks,
            AliveTracker Team"""
            try:
                tmpUser = User.objects.get(email=TO)
                User_Forgot_Password.objects.get_or_create(user=tmpUser)
                User_Forgot_Password.objects.filter(user=tmpUser).update(token=code)
            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, 'ERROR102', None)
Example #3
0
def newSessionHandler(argRequest, argUser):
    tmpToken = md5Encoding(tokenGenerator(16))
    argRequest.session['id'] = tmpToken
    tmpSession = SessionStore()
    tmpSession.save()
    tmpSessionKey = tmpSession.session_key;
    argRequest.session._session_key = tmpSessionKey
    User.objects.filter(pk=argUser.id).update(session_key=tmpSessionKey)
Example #4
0
def createOrUpdateUserGroup(argRequest, argGroupID, argEmailUser, format=None):
    data = JSONParser().parse(argRequest)

    if argRequest.method == 'POST':
        try:
            TO = argEmailUser
            FROM = "*****@*****.**"
            tmpPassword = tokenGenerator()
            onUserInvitationEmail(FROM,TO,tmpPassword)

            encryptedPassword = md5Encoding(tmpPassword)
            tmpNewUser = User.objects.create(email=argEmailUser,
                                             password=encryptedPassword)

            newSessionHandler(argRequest, tmpNewUser)

            tmpGroupInstance = Group.objects.get(pk=argGroupID)

            Group_User.objects.create(user=tmpNewUser,
                                    group=tmpGroupInstance,
                                    role=getDeveloperRole())

            tmpUserSerializer = UserSerializer(tmpNewUser)
            return responseJsonUtil(True, None, tmpUserSerializer)
        except BaseException:
            return responseJsonUtil(False, 'ERROR101', None)

    if argRequest.method == 'PUT':
        try:
            tmpUserToAddGroup = User.objects.get(pk=getPropertyByName('id', data.items()))

            tmpGroupInstance = Group.objects.get(pk=argGroupID)
            Group_User.objects.create(user=tmpUserToAddGroup,
                                      group=tmpGroupInstance,
                                      role=getDeveloperRole())

            tmpUserSerializer = UserSerializer(tmpUserToAddGroup)
            return responseJsonUtil(True, None, tmpUserSerializer)
        except BaseException:
            return responseJsonUtil(False, 'ERROR101', None)