示例#1
0
def login(req):
    """ Logs in an existing user.
        Generate user alerts if:
            Either of username or password do not match.
            Account email-id is not activated yet.
        Input: s:request object.
        Output: HttpResponseRedirect object returned by redirect() function.
    """
    username = req.POST.get('username')
    password = req.POST.get('password')
    #user = authenticate(username=username, password=password)

    try:
        user = Account.objects.get(username=username)
    except ObjectDoesNotExist:
        messages.add_message(req, messages.ERROR,
                             "Invalid username or password.")
        return redirect(index)

    is_authenticated = user.check_password(password)

    if is_authenticated:
        if user.is_active:
            LOGIN(req, user)
            return redirect(index)
        else:
            messages.add_message(
                req, messages.ERROR,
                "Your account is not activated yet. Please check your email for activation link."
            )
            return redirect(index)
    else:
        messages.add_message(req, messages.ERROR,
                             "Invalid username or password.")
        return redirect(index)
示例#2
0
def login(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        user = authenticate(username=username, password=password)
        LOGIN(request, user)
        return redirect('blog:forum')
    return render(request, 'blog/login_page.html')
示例#3
0
def login(request):
    if request.method == 'POST':
        username = request.POST.get('username')
        password = request.POST.get('password')
        user = authenticate(request, username=username, password=password)
        if user is None:
            messages.error(request, "Invalid credentials")
        else:
            LOGIN(request, user)
            messages.success(request, "Welcome back!")

            return redirect(reverse('home'))
    return render(request, 'account/login.html')
示例#4
0
def login(req):
    username = req.POST.get('username')
    password = req.POST.get('password')
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            LOGIN(req, user)
            return redirect(index)
        else:
            messages.add_message(req, messages.ERROR, "Your account is not activated yet. Please check your email for activation link.")
            return redirect(index)
    else:
        messages.add_message(req, messages.ERROR, "Invalid username or password.")
        return redirect(index)
示例#5
0
def login(request):
    form = forms.LoginForm()
    error = ""
    if request.method=='POST':
            form = forms.LoginForm(request.POST)
            if form.is_valid():
                    user = authenticate(username=form.cleaned_data['username'],password=form.cleaned_data['password'])
                    if user is not None:
                            LOGIN(request,user)
                            return HttpResponseRedirect('/')
                    else:
                            error = "Invalid Password or Username"
            else:
                    error = "Please input valid credentials"
    return render(request,"UserLogin.html",{"form":form,"error":error})
示例#6
0
def signup(request):
    form = forms.SignUpForm()
    error = ""
    if request.method=='POST':
        form = forms.SignUpForm(request.POST)
        if form.is_valid():
            username = form.cleaned_data['username']
            first_name = form.cleaned_data['first_name']
            last_name = form.cleaned_data['last_name']
            password = form.cleaned_data['password']
            email = form.cleaned_data['email']
            affiliation = form.cleaned_data['affiliation']
            user = User.objects.create_user(username, password=password)
            user.save()
            donor = Donor(username=user, first_name=first_name, last_name=last_name, email=email,affiliation=affiliation)
            donor.save()
            LOGIN(request, user)
            return HttpResponseRedirect('/')
        else:
            error = "something went wrong"
    return render(request,"SignUp.html",{"form":form,"error":error})
示例#7
0
def register(request):
    if request.method == 'POST':
        username = request.POST['username']
        password = request.POST['password']
        try:
            u = User.objects.get(username=username)
            return render(
                request, 'blog/register_page.html',
                {"warning": "There is already someone with this name"})
        except ObjectDoesNotExist as exep:
            #usermanager = UserManager()
            user = User.objects.create_user(username=username,
                                            password=password)
            user.save()
            f_user = Forum_user(biogram="nothing too fancy",
                                registration_date=datetime.date.today(),
                                credentials=user)
            f_user.save()
            LOGIN(request, user)
            return redirect('blog:forum')

    return render(request, 'blog/register_page.html')
示例#8
0
def initiation(req):
    username = req.POST.get("username")
    password = req.POST.get("password")
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            user1 = Account.objects.select_related().filter(id=user.id)
            user1 = user1[0]
            filename = datetime.datetime.strftime(datetime.datetime.now(), "%Y%b%d_%H_%M_%S.txt")
            log_dir = os.path.join(settings.EXPERIMENT_LOGS_DIR, user.username)
            if not os.path.exists(log_dir):
                os.makedirs(log_dir)
            f = open(os.path.join(log_dir, filename), "a")
            f.close()

            """ Initialize Global Values """
            GlobalValues.instantaneous_time = 0
            GlobalValues.room_temp = 29 + random.uniform(-2, 2)
            GlobalValues.max_temp = 68 + random.uniform(-0.3, 0.3)

            LOGIN(req, user)
            e = Experiment()
            e.user = user
            e.log = os.path.join(log_dir, filename)
            e.save()

            boards = sbhs.Sbhs(user.coeff_ID)
            global boards

            STATUS = 1
            MESSAGE = filename
        else:
            STATUS = 0
            MESSAGE = "Your account is not activated yet. Please check your email for activation link."
    else:
        STATUS = 0
        MESSAGE = "Invalid username or password"

    return HttpResponse(json.dumps({"STATUS": STATUS, "MESSAGE": MESSAGE}))
def login(request):
    if not request.user.is_authenticated():
        if request.method == "POST":
            form = LoginForm(request.POST)
            if form.is_valid():
                user = authenticate(request,
                                    username=form.cleaned_data['username'],
                                    password=form.cleaned_data['password'])
                if user is not None:
                    LOGIN(request, user)
                    return redirect('/account/home')
                else:
                    return render(request, 'certificates/login.html',
                                  {'form': form})
            else:
                return render(request, 'certificates/login.html',
                              {'form': form})
        else:
            form = LoginForm()
            return render(request, 'certificates/login.html', {'form': form})
    else:
        return redirect('/account/home')
示例#10
0
def initiation(req):
    """ Logs in an user for conducting the experiment on the specified board.
        Input: req:request object.
        Output: HttpResponse object.
    """
    username = req.POST.get("username")
    print 'username ', username
    password = req.POST.get("password")
    print 'password ', password
    user = authenticate(username=username, password=password)
    print 'user ', user
    if user is not None:
        if user.is_active:
            user1 = Account.objects.select_related().filter(id=user.id)
            user1 = user1[0]
            user_board = user1.board

            #allows admin to access the temporary offline devices but prohibits the users to do so
            if user_board.online and (not user_board.temp_offline
                                      or user1.is_admin):
                slots = Slot.slots_now()
                slot_ids = [s.id for s in slots]
                now = datetime.datetime.now()
                bookings = user.booking_set.filter(
                    booking_date__year=now.year,
                    booking_date__month=now.month,
                    booking_date__day=now.day,
                    slot_id__in=slot_ids).select_related("slot")
                try:
                    cur_booking = bookings[0]
                    print 'cur_booking ', cur_booking
                    active_slot = cur_booking.slot
                    print 'active_slot ', active_slot
                except:
                    cur_booking = None
                    active_slot = None

                if active_slot is not None:
                    endtime = cur_booking.end_time()
                    if now < endtime:
                        filename = datetime.datetime.strftime(
                            now, "%Y%b%d_%H_%M_%S.txt")
                        logdir = os.path.join(settings.EXPERIMENT_LOGS_DIR,
                                              user.username)
                        if not os.path.exists(logdir):
                            os.makedirs(logdir)

                        f = open(os.path.join(logdir, filename), "a")
                        f.close()

                        LOGIN(req, user)

                        e = Experiment()
                        e.booking = cur_booking
                        e.log = os.path.join(logdir, filename)
                        e.save()

                        key = str(user_board.mid)
                        print 'key ', key
                        settings.boards[key]["experiment_id"] = e.id
                        # global_logfile = settings.SBHS_GLOBAL_LOG_DIR + "/" + key + ".log"
                        # with open(global_logfile, "a") as global_loghandler:
                        #     data = "\n\n===================New experiment====================\nUsername : "******"\nExperiment Id : " + str(e.id) + "\n"
                        #     global_loghandler.write(data)

                        reset(req)

                        STATUS = 1
                        MESSAGE = filename
                    else:
                        reset(req)
                        STATUS = 0
                        MESSAGE = "Slot has ended. Please book the next slot to continue the experiment."
                else:
                    STATUS = 0
                    MESSAGE = "You haven't booked this slot."
            else:
                STATUS = 0
                MESSAGE = "Your SBHS is offline. Please contact the Vlabs team."
        else:
            STATUS = 0
            MESSAGE = "Your account is not activated yet. Please check your email for activation link."
    else:
        STATUS = 0
        MESSAGE = "Invalid username or password"

    return HttpResponse(json.dumps({"STATUS": STATUS, "MESSAGE": MESSAGE}))
示例#11
0
def initiation(req):
    username = req.POST.get("username")
    password = req.POST.get("password")
    user = authenticate(username=username, password=password)
    if user is not None:
        if user.is_active:
            user1 = Account.objects.select_related().filter(id=user.id)
            user1 = user1[0]
            user_board = user1.board
            if user_board.online:
                slots = Slot.slots_now()
                slot_ids = [s.id for s in slots]
                now = datetime.datetime.now()
                bookings = user.booking_set.filter(
                    booking_date__year=now.year,
                    booking_date__month=now.month,
                    booking_date__day=now.day,
                    slot_id__in=slot_ids).select_related("slot")
                try:
                    cur_booking = bookings[0]
                    active_slot = cur_booking.slot
                except:
                    cur_booking = None
                    active_slot = None

                if active_slot is not None:
                    endtime = cur_booking.end_time()
                    if now < endtime:
                        filename = datetime.datetime.strftime(
                            now, "%Y%b%d_%H_%M_%S.txt")
                        logdir = os.path.join(settings.EXPERIMENT_LOGS_DIR,
                                              user.username)
                        if not os.path.exists(logdir):
                            os.makedirs(logdir)

                        f = open(os.path.join(logdir, filename), "a")
                        f.close()

                        LOGIN(req, user)

                        e = Experiment()
                        e.booking = cur_booking
                        e.log = os.path.join(logdir, filename)
                        e.save()

                        key = str(user_board.mid)

                        settings.boards[key]["experiment_id"] = e.id
                        reset(req)

                        STATUS = 1
                        MESSAGE = filename
                    else:
                        reset(req)
                        STATUS = 0
                        MESSAGE = "Slot has ended. Please book the next slot to continue the experiment."
                else:
                    STATUS = 0
                    MESSAGE = "You haven't booked this slot."
            else:
                STATUS = 0
                MESSAGE = "Your SBHS is offline. Please contact the Vlabs team."
        else:
            STATUS = 0
            MESSAGE = "Your account is not activated yet. Please check your email for activation link."
    else:
        STATUS = 0
        MESSAGE = "Invalid username or password"

    return HttpResponse(json.dumps({"STATUS": STATUS, "MESSAGE": MESSAGE}))