Yii1 function using - yii

I have a question about the Yii function
I have two functions
public function actionfuntion1
public function actionfuntion2
However someone has access to data from actionfuntion1 into actionfuntion2
I have used
if (strii (yii :: app () -> request-> requestUri, 'actionfuntion2') == false) {die;
To stop him, is there any other

Related

Access codes for controller methods

I dont want the users to put in method names and their parameters manually and mess with the method. Im aware i can check for unvalid inputs but what if I call a method that generates an access code and passes that into the main controller with the all the other parameters. If the access code. Then decide that access code, if valid proceed. Is this a little too much and too crazy? What other options would you suggest
Public IActionResult MainMethod(string input, string accesscode)
{
//check if access code is correct. I can figure out the decode process and stuff
}
Public IActionResult GenerateCode(string Inputt)
{
// generate a code
Return redirectToAction(“MainMethod” new {input=Inputt , accesscode=accesscode}
});
In View when a button is clicked, I call GenerateCode first
Since you pass Inputt and generated accesscode from GenerateCode to MainMethod,why not only pass input to MainMethod?And then call a method to accesscode,and then check the accesscode in MainMehtod.
public IActionResult MainMethod(string input)
{
string accesscode = GenerateCode(input);
//check if access code is correct. I can figure out the decode process and stuff
}
public string GenerateCode(string Inputt)
{
// generate a code
return accesscode;
}

Call to a member function addUnauthenticatedActions() on null (CakePHP Authentication)

I am trying to implement the CMS Tutorial - Authentication for CakePHP and I am only trying to implement the login page up till now but it is giving me an error on this line
$this->Authentication->addUnauthenticatedActions(['login']);
Error:
Call to a member function addUnauthenticatedActions() on null
UsersController:
public function beforeFilter(\Cake\Event\EventInterface $event){
parent::beforeFilter($event);
// Configure the login action to not require authentication, preventing
// the infinite redirect loop issue
$this->Authentication->addUnauthenticatedActions(['login']);
}
public function initialize() :void{
$this->loadComponent('Flash');
$this->loadComponent('Authentication.Authentication');
}
in your appController use $this->Authentication->addUnauthenticatedActions(['someactions']);
and if you want to use UnauthenticatedActions in your controller you nit to put
public function beforeFilter(EventInterface $event)
{
parent::beforeFilter($event);
$this->Authentication->allowUnauthenticated(['actions']);
}

Yii Rest api url manager

I am not able to find the logic behind the url manager. Can any body tell me about the given url calling in Rest pattern. I have too many get methods in my Controller with single parameter.
This is my Original url : localhost/project/api/event/getevent/event_id/1
api is Module
event is Controller
getevent is Controller action name
event_id is parameter 1
I want to convert this to Rest pattern localhst/project/api/event/1
//Updated code..
all are related to same Model..............
//Search by Event id
public function actionByEventId(){
$model->byEventId();
}
//Retrieve user's events by User id
public function actionByUserId()
{
$model->userEvents();
}
//Search for event by code
public function actionByEventcode()
{
$model->byEventCode();
}
Add this rule:
'api/<controller:\w+>/<action:\w+>/<id:\d+>' => 'api/<controller>/by<action>'
And add the $id your actions:
public function actionByEventId($id) {
}
public function actionByUserId($id) {
}
Now if you call localhst/project/api/event/eventid/1 Yii will call the actionByEventId in your event-Controller with $id as 1

Pass parameter values from JQuery to VB.Net Function

I have here a vb.net function which accepts 2 parameters and the values that will be passed here will be coming from my jquery code. Is it possible to pass the values from jquery to vb.net? I've already read some solutions but they point out that the vb.net method should be a webmethod. In my case, the vb function is not a web method so that strikes that out. Below are some snippets of my code. Hope you could help me on this.
JQuery code
$('#TextBox_PRVNo').keypress(function (event) {
if (event.keyCode == '13') {
//basically, pass values from textbox 1 and textbox 2 to VoucherNotClaimed() method
}
});
VB.Net code
Private Function VoucherNotClaimed(ByVal strVoucherType, ByVal strPRVNo) As Boolean
' TODO: Search in database
Return True
End Function
You don't need a web service to decorate your methods with the WebMethod attribute. If you do it on a regular page, you create a so-called page method. In a nutshell:
Create a public static method in your page, decorated with the WebMethod attribute:
<WebMethod()> _
Public Shared Function VoucherNotClaimed(ByVal strVoucherType, ByVal strPRVNo) As Boolean
' TODO: Search in database
Return True
End Function
Add a ScriptManager to your ASPX page and set its EnablePageMethods property to True. Also, make sure your web.config is set up properly.
Call your method with JavaScript:
var claimed = PageMethods.VoucherNotClaimed(voucherType, prvNo);
You can find a more detailed explanation in the following MSDN article:
Exposing Web Services to Client Script (Section Calling Static Methods in an ASP.NET Web Page)
Note that this is the classic way to do it. With JQuery, it is also possible to call the page method without a ScriptManager; a quick Google search for page method jquery yields a huge amount of blog entries going into every possible detail.

Silverlight RIA Application that only accepts registered users

I have implemented the RIA WCF side to authenticate with Forms Authentication and everything works from the client as expected.
This application should only allow registered users to use it (users are created by admin - no registeration page).
My question is then, what (or where) should be the efficient way to make the authentication; it has to show up at application start up (unless remember me was on and cookie is still active) and if the user logs out, it should automatically get out the interface and return to login form again.
Update (code trimmed for brevity):
Public Class MainViewModel
....
Public Property Content As Object 'DP property
Private Sub ValidateUser()
If Not IsUserValid Login()
End Sub
Private Sub Login()
'I want, that when the login returns a success it should continue
'navigating to the original content i.e.
Dim _content = Me.Content
Me.Content = Navigate(Of LoginPage)
If IsUserValid Then Me.Content = _content
End Sub
End Class
I saw you other question so I assume you're using mvvm. I accomplish this by creating a RootPage with a grid control and a navigation frame. I set the RootVisual to the RootPage. I bind the navigation frames source to a variable in the RootPageVM, then in the consructor of RootPageVM you can set the frame source to either MainPage or LoginPage based on user auth. RootPageVM can also receive messages to control further navigation like logging out.
Using MVVM-Light.
So, in the RootPageView (set as the RootVisual), something like:
public RootPageViewModel()
{
Messenger.Default.Register<NotificationMessage>
(this, "NavigationRequest", Navigate);
if (IsInDesignMode)
{
}
else
{
FrameSource =
WebContext.Current.User.IsAuthenticated ?
"Home" :
"Login";
}
}
And a method for navigation:
private void Navigate(NotificationMessage obj)
{
FrameSource = obj.Notification;
}
In the LoginViewModel:
if (loginOperation.LoginSuccess)
{
Messenger.Default.Send
(new NotificationMessage(this, "Home"), "NavigationRequest");
}