TYPO3 Plugin - One action public access and one private - authentication

I'm developing an extension that have both, a list of records (action show) and a form to send a new record (action new).
The list must be for public access, but the form must require a login form (I'm using the login form content type that comes with TYPO3).
I have tried using the Access Tab for the plugin selecting Show at any Login but it applies to the entire plugin not for each action.
Currently, this is how the page looks like:
How could I get to display the login form only when someone tries to create a new record?
Note: The extension is based on Extbase and Fluid. The target version is TYPO3 6.2.

The easiest would be to split the actions in different "views" with switchableControllerActions in your flexform. Then you would need to place separate plugins on two different pages, that way you can have different access configuration for the plugins. If you don't know how to adjust the flexform, you can post the content of it here.
The other way would be to make a check inside the controller, but i would only use it if you have a lot of different roles you need to check.
if ($this->loginUser === null && $GLOBALS['TSFE']->loginUser && !empty($GLOBALS['TSFE']->fe_user->user['uid'])) {
// the user is logged in
} else {
// return '' as action content
return '';
}

Related

Prestashop 1.6: how to load a different template after an admin form submission?

I'm new to Prestashop and currently working on a custom admin module in 1.6.
My scenario is, users can load orders to this module/admin controller and from the list they can select which ever order they like using 'Select All' checkbox selector.
And then these selected order ids are submitted back to admin controller to be displayed on a different template with full information in a form.
And then again this form will be submitted to a third party API for further processing.
Now my problem is I can get the order listing to my admin controller and get them submitted back to the same controller. But I do not know how to switch to a different template to display in a form.
And also how to call a different method to process and export once second form substitution is done.
Any advice would be greatly appreciated.
Thanks in advance
Roshan
In your AdminController extend the method initContent with a condition that is you need to check if a certain button was pressed. Something like
public function initContent()
{
if (Tools::isSubmit('the_button')) {
'do what you want to do'
}
parent::initContent();
}
if you want to redirect to a different controller use Tools::redirectAdmin() and set the path of redirection like Context::getContext()->link->getAdminLink('your_another_controller', true), also you can send all necessary data with the third parameter of the method(array)
public function initContent()
{
if (Tools::isSubmit('the_button')) {
Tools::redirectAdmin(
Context::getContext()->link->getAdminLink('your_another_controller', true, $orders)
);
}
parent::initContent();
}
You can use as many conditions, inside the method, as you need so I hope it will help you in all your cases.

How to make required fields using JS

I have a SharePoint Form. How can I make a required field( people picker and date) using Java Scripts ? Thanks in advance
Check the OOTB options first. Obviously a list field marked required will not submit until it's filled in.
You can also setup validation in list setting under validation settings. Enter a formula that can evaluate to TRUE to pass validation (Title = "TitleXYZ"). Custom error text can also be added.
There are endless options using JavaScript. The basic SharePoint forms model (assuming your validating on the submit event) uses the PreSaveItem function:
function PreSaveItem()
{
if ("function"==typeof(PreSaveAction))
{
return PreSaveAction();
}
return true;
}
PreSaveAction function also allows override behavior for the Save button. For example:
function PreSaveAction() {
return ifValidSSN();
}
You can find a good example of using this function
here
If you want more of a framework there are multiple jQuery validation plugins you can try. I recommend the jquery Validation plugin
If you want some examples of using this plugin let me know

Calling a controller method (from an external email link) that does not return a View, but simply exits

I have an MVC 4 Razor intranet app using Windows credentials where a new user must register (existing users are automatically redirected to the main user page). This generates an approval request email to the admin and returns a view with an Exit button simply saying your application has been submitted. The user then closes the app.
The email is in HTML and presents the user's entered data and has Approved or Declined selections. It then has a button to invoke code to insert the user into the Members table (if accepted) and return an email to the user with the decision.
Since some time may transpire between the app mailing the admin and the admin making the decision, the session will originally terminate. I need to have the email invoke a method to persist the new user, email the decision, and then simply exit. It will not involve the browser in any way, so no Views are involved. I could write this as a background console app, but that would involve duplicating a lot of code in the MVC app - with referential integrity issues on bug fixes or updates.
How can I write a method in the Controller that can be invoked by a link in the email as if from a browser that does the work and then exits without returning anything to a browser?
If I make the method an ActionResult method and return new EmptyResult() or return(null) I assume it will try to return an empty page to nowhere.
Can I alternatively construct a method in my Controller, where it has access to all of the support code, like?
public void EnrollMember(Member member, bool decision)
{
if (decision == true)
{
// insert new user into Members table
// generate accepted email
}
else
{
// generate declined email
}
}
and then just link to it the same way I link to Index(), /MyController/EnrollMember(...)?
There is no main() in the app since it is an ASP.NET MVC app, and I don't know how to terminate the app from within a Controller method without trying to return something, instead of from a View in the browser.
I'm a long-time programmer, but a .NET newbie so this probably has a simple answer.
The "view" is just the response. You don't necessarily have to return a view, but you must return a response. There's no way around that. If the link opens in a browser, then something will be displayed, regardless. Even if you were to just return an empty ContentResult, at least a blank page will be displayed in the browser.
To achieve something akin to what you're looking for, your best bet would be to return an HTML document with just a simple bit of JavaScript that will act to close the window:
<html>
<body>
<script>
window.close();
</script>
</body>
</html>

How does Opencart Module saves its settings?

Hey guys I ran into a bit of a problem with module I am developing for OpenCart v1.5.6.4. This is what I have in Admin section for module settings.
As you can see I built in extra tabs where I want to give user the ability to specify extra options which will be used to build out a prescription form on the Catalog side.
Problem is how do I go about Save extra data from each additional tab to a custom table when user click on Save button?
Is there a special function that gets called when Save button is clicked that I could implement myself?
Eh, I guess I was a bit tired last night to realise that this section of code defined in index() handles saving of module setting to the database:
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validate()) {
//save module settings
$this->model_setting_setting->editSetting('prescripts', $this->request->post);
//mark of success
$this->session->data['success'] = $this->language->get('text_success');
//redirect back to module page
$this->redirect($this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'));
}
So all i need to do is stuff my custom code in here and I am done with Admin controller.

Disable Links to My Site profiles in Sharepoint 2010

I would like to utilize some of the social collaboration features in Sharepoint 2010, such as the Noteboard webpart and tagging, but do not want to use the My Site profile pages.
I have already built a custom control that redirects from the userdisp.aspx page to a custom user profile page. I would like to continue to use that custom profile page. However, it seems like user profile links that are generated by the Noteboard webpart, for example, go directly to the /Sites/MySites/person.aspx page without being routed through the /_layouts/userdisp.aspx page. So my profile redirect control doesn't catch it.
In Sharepoint Central Admin, under Manage Service Applications > User Profile Service Application > Manage User Permissions, I have only checked the box for "Use Social Features", not "Create Personal Site," so I am not sure why the profile page is not linking to the old userdisp.aspx page.
Is it possible to redirect these links back to the userdisp.aspx page?
It appears to be hardcoded into the webpart.
I looked at Microsoft.SharePoint.Portal.WebControls.SocialCommentControl and the link comes from UserProfile.PublicUrl, which is defined as:
public override Uri PublicUrl
{
get
{
string userProfileUrl = UserProfileGlobal.GetUserProfileURL(
this.m_objManager.UserProfileApplicationProxy,
this.m_objManager.PartitionID,
"?accountname=",
this.m_UserProfileFields["AccountName"].ToString());
if (!string.IsNullOrEmpty(userProfileUrl))
return new Uri(userProfileUrl);
else
return (Uri) null;
}
}
which eventually calls:
internal static string GetUserProfileURL(string profileWebUrl, string strIdentifier, string strValue)
{
if (string.IsNullOrEmpty(profileWebUrl))
return (string) null;
else
return PersonalSpaceGlobal.EnsureTrailingSlash(profileWebUrl)
+ "Person.aspx"
+ strIdentifier
+ (strIdentifier.Equals("?accountname=", StringComparison.OrdinalIgnoreCase)
? SPHttpUtility.UrlKeyValueEncode(strValue).Replace(":", "%3A")
: SPHttpUtility.UrlKeyValueEncode(strValue));
}
I can think of two workarounds:
Add jQuery to your page to change the URL (selector = span.socialcomment-username > a)
Create your own webpart containing a custom control that inherits from SocialCommentControl, which overrides RenderComment.
Overriding RenderComment is probably going to be messy. You will need to copy the decompiled code for the method just to change the following into your own code:
SocialCommentControl._GetProperty(
comment,
SocialCommentControl.SocialCommentProperty.PublicPage)
Hopefully, there are no internal method calls within RenderComment's 67 lines of code. Otherwise, it is going to be a lot more difficult to implement. It would be a lot easier if you could simply override _GetProperty, but unfortunately, it is a static method.
All of that to say, I would probably recommend the jQuery option over extending SocialCommentControl.