So I'm trying to create a bot to add roles to a targeted user with the command "r.accept insert username here" but I don't know how to get the bot to target the user in question. So where do I place it?
package com.kotadajedi.reina.listeners;
import net.dv8tion.jda.api.entities.Role;
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
import net.dv8tion.jda.api.hooks.ListenerAdapter;
public class EventListener extends ListenerAdapter {
public void onMessageReceived(MessageReceivedEvent event) {
String message = event.getMessage().getContentRaw();
if(message.contains("r.accept")) {
event.getGuild().addRoleToMember(event.getMember(), (Role) event.getJDA().getRolesByName("new role", true));
}
}
}
I understand that the title of the question may be vague but then that's the best way I could come up with to explain my issue at hand.
I'm overriding the OnActionExecuting function to manage my session related activities and allow/ deny requests to authorized/ unauthorized users, respectively. Along with tracking of the session, I'm also using the OnActionExecuting to load user available features for the current page into a temporary class and accessing from the view using ajax call.
namespace MyApp.Controllers
{
public class TESTController : Controller
{
[SessionTimeout]
public ActionResult Index()
{
return this.View();
}
}
}
public class SessionTimeoutAttribute : ActionFilterAttribute
{
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
HttpContext ctx = HttpContext.Current;
if (ctx.Session["AppUser"] == null)
{
// Redirect to the login page
// Or deny request
}
else
{
var controllerName = filterContext.ActionDescriptor.ControllerDescriptor.ControllerName;
var actionName = filterContext.ActionDescriptor.ActionName;
var methodType = ((ReflectedActionDescriptor)filterContext.ActionDescriptor).MethodInfo.ReturnType;
if (methodType == typeof(ActionResult))
{
// Load all user access rights for the current page into a temporary memory
// by using the Action and Controller name
}
}
base.OnActionExecuting(filterContext);
}
}
The above works like a charm.. But the issue is when the user clicks on the back button of the browser or hits the backspace key. In that case, the OnActionExecuting function is never called for the ActionResult and further I am unable to load the current page access rights for the user.
Thanks & Regards,
Kshitij
Adding the following to my ActionResult made the above code to work.
[SessionTimeout]
[OutputCache(Duration = 0, NoStore = true)]
public ActionResult SomeView()
{
return this.View();
}
I'm automating Web UI testing for an angular 2 website. However, I got a problem when wanting to check if the login step is successful. It always pass even I put the wrong password or the wrong XPath for logout button.
This element just exists when we login successfully. As i mentioned before, i intentionally put wrong password and even wrong xpath for btt_Logout (xbutton not button) so this element cannot exist but it's still true.
I don't understand what the problem is even I try a lot of things. I just change toBe(true) to toBe(false) but it still passes :). It seems to be that this expect does not work. I don't understand why
import {browser, ExpectedConditions as EC, $, $$, element,by} from 'protractor'
import { Login } from '../page_objects/login.page';
import { helper } from '../helpers/helper'
declare let expect:any;
describe('Testing Login ', function () {
beforeEach(async () => {
})
it('Go to loginpage', async function () {
//Go to Login Page
Login.openHomePage();
});
it('Login to the page', async function () {
//Enter username, password and press OK. It work well.
Login.login("admin","admin#123");
//Waiting to see btt_Logout. Problems in here. It always true even i make XPath of btt_Logout wrong or make password wrong. I check/
browser.wait(EC.presenceOf(Login.btt_Logout), 30000).then(function () {
expect((Login.btt_Logout).isPresent()).toBe(true);
}, function (error) {
expect(true).toBe(false);
});
});
afterAll(()=> {
helper.cleanUp();
console.warn(`Test finished!`)
})
})
Login Page Object:
import {browser, ExpectedConditions as EC, $, $$, element, by, ElementFinder} from 'protractor'
import {BasePage} from './base.page'
require('../helpers/waitReady.js');
class LoginPage extends BasePage {
//Internal element
protected txt_LoginUsername: ElementFinder = element(by.id('username'));
protected txt_LoginPassword: ElementFinder = element(by.id('password'));
protected btt_LoginSubmit: ElementFinder = element(by.xpath("//button[contains(#class,'btn-submit')]"));
//External element
public login(Username, Password) {
this.txt_LoginUsername.sendKeys(Username);
this.txt_LoginPassword.sendKeys(Password);
this.btt_LoginSubmit.click();
}
}
export const Login = new LoginPage();
Base Page:
import {browser, ExpectedConditions as EC, $, $$, element, by, ElementFinder} from 'protractor'
require('../helpers/waitReady.js');
export abstract class BasePage {
protected url: string = '' // Will be same as baseUrl by default.
public btt_Logout: ElementFinder = element(by.xpath("//xbutton[contains(#class,'btn-logout')]"));
async openHomePage() {
return await browser.get(this.url)
}
async openUrl(webUrl) {
return await browser.get(webUrl)
}
}
Result:
Started
JASMINE STARTING:
» Testing Login
▻ Go to loginpage
. ✓ Go to loginpage (16 s)
▻ Login to the page
. ✓ Login to the page (0.234 s)
Test finished!
2 specs, 0 failures
Finished in 16.599 seconds
Summary *
Executed 2 out of 2 specs in 17 s
PASSED 2 ( 100% )
FAILED 0 ( 0% )
SKIPPED 0 ( 0% )
[22:38:58] I/launcher - 0 instance(s) of WebDriver still running
[22:38:58] I/launcher - chrome #01 passed
I believe it's because you're using isPresent() in expect((Login.btt_Logout).isPresent()).toBe(true); which checks if the element exists so it returns true.
Your expect isn't getting triggered, not to mention the wait clutters up your test. Also, presenceOf only checks the element is in the dom, not it's visibility.
Try throwing the wait in your login() method (which is probably the right place for it anyway), and making the logout button public. Protractor/jasmine will handle the wait for you in the expect.
import {browser, ExpectedConditions as EC, $, $$, element, by, ElementFinder} from 'protractor'
import {BasePage} from './base.page'
require('../helpers/waitReady.js');
class LoginPage extends BasePage {
//Internal element
protected txt_LoginUsername: ElementFinder = element(by.id('username'));
protected txt_LoginPassword: ElementFinder = element(by.id('password'));
protected btt_LoginSubmit: ElementFinder = element(by.xpath("//button[contains(#class,'btn-submit')]"));
public btt_Logout: ElementFinder = element(by.xpath("//xbutton[contains(#class,'btn-logout')]"));
//External element
public login(Username, Password) {
this.txt_LoginUsername.sendKeys(Username);
this.txt_LoginPassword.sendKeys(Password);
this.btt_LoginSubmit.click();
return browser.wait(EC.visibilityOf(this.btt_Logout), 30000, 'timeout: waiting for login');
}
}
export const Login = new LoginPage();
Then your test would be...
it('Login to the page', async function () {
Login.login("admin","admin#123");
expect(Login.btt_Logout.isDisplayed()).toBe(true);
});
I just found that my issue is that I put the element login_button in base_page and it makes a big issue. When protractor opens, it will be looking for this element and it causes we must wait for a long time. – Mike just now edit
Have you checked if that certain object is not present in the HTML/CSS?
There are cases where in if you are checking a TEXT,
the element might still be there and only displays EMPTY value,
that's why it does not look visible but isPresent and isDisplayed.
im trying to create mvc application with role based authorization. Currently i want 2 roles only, admin and user. I already make simple authorization work, but still without role. I already search so many reference in internet but still cant find one that works with me. Please help, thank you.
[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult Login(LoginViewModel model)
{
if (ModelState.IsValid)
{
string loginquery = "select UserId,Password,Roles from UserAcc where "
+ "userId = #p0 and Password = #p1";
var a= db.User.SqlQuery(loginquery,model.userid, model.password).Count() ;
if (a>0)
{
FormsAuthentication.SetAuthCookie(model.userid, false);
Session["userid"] = model.userid.ToString();
return RedirectToAction("Index", "Employee");
}
else { return RedirectToAction("Login"); }
}
else
{
ModelState.AddModelError("", "EmailId or Password Incorrect.");
}
return View(model);
}
I want the program to set role authorization based on role field in database
SELECT TOP 1000 [UserId]
,[Password]
,[Roles] FROM [ESS].[dbo].[UserAcc]
And i want to filter my controller like this
namespace TEST2.Controllers{[Authorize(Roles = "user")]
public class EmployeeController : Controller
{
Thankyou,
I'm trying to set up a simple login system, but I'm having a particular problem that I can't solve. I have the following pages that perform self-explanatory actions. They are bookmarked for easy access.
cake/ (home page; must be logged in)
cake/login (must be logged in)
cake/logout (must be logged in)
cake/add (must be logged in)
All seems to work except when I preform the following sequence of actions:
1. log in
2. go to cake/logout to log out (login works immediately after this step)
3. go to cake/logout again immediately
4. attempt to log in but cake/login is just re-displayed and I'm not logged in
5. attempt to log in again and it is successful
I have noticed that $this->Session->flash('auth') is FALSE after step 3 but it is not false after 4. I tried destroying the session before or after logging out with no effect. Any ideas?
My code bits are below:
class UsersController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow('add');
}
public function add() {
if (!empty($this->data)) {
$this->User->create();
if ($this->User->save($this->data)) {
$this->Session->setFlash('User created!');
$this->redirect(array('action'=>'login'));
} else {
$this->Session->setFlash('Please correct the errors');
}
}
}
public function login() {
}
public function logout() {
$this->Session->destroy(); // makes no difference
$this->redirect($this->Auth->logout()); // redirected to login() by default
}
}
class AppController extends Controller {
public $components = array('Auth', 'Session');
}
I think that you are being redirected to the logout screen after your login.
When you go to a page you don't have access to (like the logout screen), you are redirected to login.
Once you enter name and password, you are taken back to your original request.
When that original request happens to be the logout page, logout occurs and you are sent back to the login.