Ejemplo n.º 1
0
def session(request, token="QWER"):
    #this_session = Session.objects.get(token=token)
    this_session = Session()
    this_session.lifetime = 10
    this_session.save()
    return render(request, template_name="session.html",
                  context={'token': token, 'session': this_session, 'users': this_session.users.all()})
Ejemplo n.º 2
0
def log_in(request):
    if request.user.is_authenticated(): # Check to see if the user is already logged in
        return redirect('home')

    if request.method == "POST":
        username = request.POST['username']
        password = request.POST['password']

        user = authenticate(username=username, password=password)

        if user is not None:
            if user.is_active:
                login(request, user)

                # Create new Session
                session = Session(user=username, date=datetime.now())
                session.save()
                # Save Session ID to cookie
                request.session['session'] = session.id

                # Redirect to home
                return redirect('home')
            else:
                messages.error(request, 'Oops!  User is not active')
                return render_to_response("login.html", locals(), context_instance=RequestContext(request))
        else:
            messages.error(request, 'Oops!  User does not exist')
            return render_to_response("login.html", locals(), context_instance=RequestContext(request))

    return render_to_response("login.html", locals(), context_instance=RequestContext(request))
Ejemplo n.º 3
0
def create_session(is_active=True):
    session_id = str(uuid4())

    new_session = Session(
        session_id=session_id,
        is_active=is_active,
    )
    new_session.save()

    return new_session.as_dict()
Ejemplo n.º 4
0
def create_session(request: HttpRequest):
    if request.method == 'POST':
        form = CreateSession(request.POST)
        rand = ''.join([choice(ascii_letters + digits) for n in range(5)])
        NewSession = Session(name=form.data['name'], token=rand, lifetime=24, language=form.data['language'])
        if form.is_valid():
            NewSession.save()
            NewSession.users.add(*[request.user])
        return HttpResponseRedirect("/session/" + NewSession.token)
    return render(request, template_name='create_session.html')
Ejemplo n.º 5
0
def reset_session(request):

    username = request.user.username

    # Create new Session
    session = Session(user=username, date=datetime.now())
    session.save()
    # Save Session ID to cookie
    request.session['session'] = session.id

    # Redirect to home
    return redirect('home')
def get_user_from_validated_data(data,check_couch=False):
    user = None
    try:
        hash = data['hash']
        session = Session.getSession(hash)
        del data['hash']
        user = session.user
    except Exception:
        raise MY_REST_EXCEPTION(detail="Wrong session", status=HTTP_WRONG_SESSION)
    if check_couch == True:
        if not user.is_couch == True:
            raise MY_REST_EXCEPTION(detail="Wrong type of user", status=HTTP_YOUR_TYPE_OF_USER_CANNOT_DO_THIS)
    return user
def register(request):
    """
    ---
    response_serializer: IdSerializer
    request_serializer: UserRegisterSerializer
    """
    sdata = get_validated_serializer(request=request, serializer=UserRegisterSerializer).validated_data
    password = sdata['password']
    del sdata['password']
    user = User(**sdata)
    user.set_password(password)
    user.save()
    session = Session.get_for_user(user)
    return Response( IdSerializer({"hash": session.hash, 'id':user.pk}).data , status=HTTP_OK)
def login(request):
    """
    ---
    response_serializer: IdSerializer
    request_serializer: UserLoginSerializer
    responseMessages:
        - code: HTTP_DOES_NOT_EXIST
          message: User doesn't exist
    """
    sdata = get_validated_serializer(request=request, serializer=UserLoginSerializer).validated_data
    user = User.objects.filter(phone=sdata['phone']).first()
    if ( user is None or not user.check_password(sdata['password'])):
        return Response("No user with such user", status=HTTP_DOES_NOT_EXIST)
    session = Session.get_for_user(user)
    return Response( IdSerializer({"hash": session.hash, 'id':user.pk}).data , status=HTTP_OK)
Ejemplo n.º 9
0
def get_user_from_validated_data(data, check_couch=False):
    user = None
    try:
        hash = data['hash']
        session = Session.getSession(hash)
        del data['hash']
        user = session.user
    except Exception:
        raise MY_REST_EXCEPTION(detail="Wrong session",
                                status=HTTP_WRONG_SESSION)
    if check_couch == True:
        if not user.is_couch == True:
            raise MY_REST_EXCEPTION(
                detail="Wrong type of user",
                status=HTTP_YOUR_TYPE_OF_USER_CANNOT_DO_THIS)
    return user
Ejemplo n.º 10
0
def register(request):
    """
    ---
    response_serializer: IdSerializer
    request_serializer: UserRegisterSerializer
    """
    sdata = get_validated_serializer(
        request=request, serializer=UserRegisterSerializer).validated_data
    password = sdata['password']
    del sdata['password']
    user = User(**sdata)
    user.set_password(password)
    user.save()
    session = Session.get_for_user(user)
    return Response(IdSerializer({
        "hash": session.hash,
        'id': user.pk
    }).data,
                    status=HTTP_OK)
Ejemplo n.º 11
0
def login(request):
    """
    ---
    response_serializer: IdSerializer
    request_serializer: UserLoginSerializer
    responseMessages:
        - code: HTTP_DOES_NOT_EXIST
          message: User doesn't exist
    """
    sdata = get_validated_serializer(
        request=request, serializer=UserLoginSerializer).validated_data
    user = User.objects.filter(phone=sdata['phone']).first()
    if (user is None or not user.check_password(sdata['password'])):
        return Response("No user with such user", status=HTTP_DOES_NOT_EXIST)
    session = Session.get_for_user(user)
    return Response(IdSerializer({
        "hash": session.hash,
        'id': user.pk
    }).data,
                    status=HTTP_OK)
Ejemplo n.º 12
0
def _get_session(session_id):
    return Session.get(session_id)
Ejemplo n.º 13
0
def update_session(session_id, **kwargs):
    session = Session(session_id=session_id, **kwargs)
    session.save()
    return session.as_dict()
Ejemplo n.º 14
0
def setup_dynamo():
    Game.create_table()
    Session.create_table()
    Participation.create_table()
Ejemplo n.º 15
0
    except:
        pass
    l.save()
    
f.close()

## sessions

f = open('/Users/dimitriosalikaniotis/Sites/llc/llc_site/llc/utils/sessions.txt')
f2 = open('/Users/dimitriosalikaniotis/Sites/llc/llc_site/llc/utils/paper_sessions.txt')
d = {}
for i, s in enumerate(f2, 1):
    d[i] = map(int, s.strip().split('\t'))

for line in f:
    s = Session()
    newline = map(int, line.strip().split('\t'))
    day = newline[1]
    month = newline[2]
    year = newline[3]
    loc = newline[4]
    date = datetime.date(year=year, month=month, day=day)
    s.day = date
    s.location = Location.objects.get(pk=loc)
    s.save()
    for i, (k, v) in enumerate(d.iteritems(), 1):
        if s.pk in v:
            s.paper.add(Paper.objects.get(pk=i))
    s.save()
    
f.close()