Ejemplo n.º 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)
Ejemplo n.º 2
0
def projectDeserializer(argData, argGroupID):
    tmpProject = Project(name=getPropertyByName('name', argData.items()),
                         description=getPropertyByName('description', argData.items()),
                         created=getPropertyByName('created', date.today()),
                         entity_status=0,
                         group=Group.objects.get(argGroupID))
    return tmpProject
Ejemplo n.º 3
0
def createProjectListDTOObject(argProject, argUserList, argProjectID):
    tmpProjectUserListDTO = ProjectUserListDTO(id=argProjectID,
                                               name=getPropertyByName('name', argProject.data.items()),
                                               created=getPropertyByName('created', argProject.data.items()),
                                               description=getPropertyByName('description', argProject.data.items()),
                                               groupID=getPropertyByName('group', argProject.data.items()),
                                               users=argUserList)
    tmpProjectUserListDTOSerializer = ProjectUserListDTOSerializer(tmpProjectUserListDTO)
    return tmpProjectUserListDTOSerializer
Ejemplo n.º 4
0
def logDeserializer(argData, argUser, argDate):
    tmpLog = Log(activity=getPropertyByName('activity', argData.items()),
                 time=getPropertyByName('time', argData.items()),
                 date=argDate,
                 user=argUser,
                 project=Project.objects.get(pk=getPropertyByName('project', argData.items())),
                 group=Group.objects.get(pk=getPropertyByName('group', argData.items())),
                 entity_status=0)
    return tmpLog
Ejemplo n.º 5
0
def register_user(request):
    try:
        data = JSONParser().parse(request)
        tmpNewUser = User.objects.create(email=getPropertyByName('email', data.items()),
                                         password=getPropertyByName('password', data.items()));
        newSessionHandler(request, tmpNewUser);
        tmpUserSerializer = UserSerializer(tmpNewUser)
        return responseJsonUtil(True, None, tmpUserSerializer)
    except BaseException:
        return responseJsonUtil(False, 'ERROR101', None)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
def update_user(request, pk, format=None):
    try:
        user = User.objects.get(pk=pk)
    except User.DoesNotExist:
        return responseJsonUtil(False, 404, None)
    data = JSONParser().parse(request)
    tmpName = getPropertyByName('name', data.items())
    tmpPassword = getPropertyByName('password', data.items())
    user.name = tmpName
    user.password = tmpPassword
    user.entity_status = 0
    user.save()
    serializer = UserSerializer(user, data=data)
    return responseJsonUtil(True, None, serializer)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
def setPassword(request, format=None):
    if request.method == 'PUT':
        if not userAuthentication(request):
            return responseJsonUtil(False, 'ERROR103', None)
        data = JSONParser().parse(request)
        tmpPassword = getPropertyByName('password', data.items())
        User.objects.filter(session_key=request.session._session_key).update(password=tmpPassword)
        tmpUser = getUserByRequest(request)
        tmpSerializer = UserSerializer(tmpUser)
        return responseJsonUtil(True, None, tmpSerializer)
Ejemplo n.º 10
0
def user_authentication(argRequest, format=None):
    try:
        tmpData = JSONParser().parse(argRequest)
        tmpEmail = str(getPropertyByName('email', tmpData.items()))
        tmpPassword = str(getPropertyByName('password', tmpData.items()))
        tmpUser = User.objects.exclude(entity_status = 1).get(password=tmpPassword, email=tmpEmail)

        if argRequest.method == 'POST':

            if 'id' not in argRequest.session or argRequest.session._session_key == locales.INVALID_SESSION_KEY:
                newSessionHandler(argRequest, tmpUser)
            else:
                User.objects.filter(pk=tmpUser.id).update(session_key=argRequest.session._session_key)

            tmpSerializer = UserSerializerDTO(tmpUser)
            return responseJsonUtil(True, None, tmpSerializer)
    except User.DoesNotExist:
        return responseJsonUtil(False, 'ERROR400', None)
    except BaseException:
        return responseJsonUtil(False, 'ERROR000', None)
Ejemplo n.º 11
0
def update_default_group(request, pk, format=None):
    try:
        user = User.objects.get(pk=pk)
    except User.DoesNotExist:
        return responseJsonUtil(False, 404, None)
    data = JSONParser().parse(request)
    tmpDefaultGroup = getPropertyByName('default_group', data.items())
    user.default_group = tmpDefaultGroup
    user.save()
    serializer = UserSerializer(user, data=data)
    return responseJsonUtil(True, None, serializer)
Ejemplo n.º 12
0
def saveProject(argRequest, argGroupId, format=None):
    try:
        if not userAuthentication(argRequest):
            return responseJsonUtil(False, 'ERROR103', None)

        tmpData = JSONParser().parse(argRequest)
        if argRequest.method == 'POST':
            tmpNewProject = Project.objects.create(name=getPropertyByName('name', tmpData.items()),
                                 description=getPropertyByName('description', tmpData.items()),
                                 created=date.today(),
                                 entity_status=0,
                                 group=Group.objects.get(pk=argGroupId))
            updateUserListInProject(tmpData, tmpNewProject.id)
            tmpSerializer = ProjectSerializer(tmpNewProject)
            return responseJsonUtil(True, None, tmpSerializer)
        if argRequest.method == 'PUT':
            Project.objects.filter(id=getPropertyByName('id', tmpData.items())).update(
                name=getPropertyByName('name', tmpData.items()),
                description=getPropertyByName('description', tmpData.items()),
                group=Group.objects.get(pk=argGroupId))
            updateUserListInProject(tmpData, getPropertyByName('id', tmpData.items()))
            return responseJsonUtil(True, None, None)
    except Project.DoesNotExist:
        return responseJsonUtil(False, 'ERROR500', None)
    except BaseException:
        return responseJsonUtil(False, 'ERROR000', None)
Ejemplo n.º 13
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)
Ejemplo n.º 14
0
def insertProjectUsers(argProjectUsers, argProjectID):
    tmpList = getPropertyByName('users', argProjectUsers.items())
    for tmpCont in range(len(tmpList)):
        Project_User.objects.create(user=User.objects.get(pk=getPropertyByName('id', tmpList[tmpCont].items())),
                                    project=Project.objects.get(pk=argProjectID),
                                    role=Role.objects.get(name=getPropertyByName('role', tmpList[tmpCont].items())))
Ejemplo n.º 15
0
def noteDeserializer(argData):
    tmpNote = Note(note=getPropertyByName('note', argData.items()),
                   log=Log.objects.get(pk=getPropertyByName('log', argData.items())),
                   entity_status=0)
    return tmpNote