Php Magento - How to redirect user to a custom store after login - magento-1.8

I want to redirect a user after sign in to a store after checking customer group type. Now in login.phtml file, where should i make change? Where should i apply my condition of checking of customer type in the code? please help.

After successful sign in login.phtml file will not be executed.
So you need to override this controller class
Mage_Customer_AccountController
if you don't know how to override controller then refer this link
Magento: Overriding customer account controller
After that write your code like this in your new AccountController class
public function _loginPostRedirect(){
$session = $this->_getSession();
Mage::log($session->getCustomerGroupId()); }
once log in from frontend and check your log /var/log/system.log you will find customer group id

Related

Serenity-Cucumber, how to use the same scenario step across multiple feature files

Using Serenity-Cucumber, I am trying to build a test suite so that I can reuse the step definitions (Given, When, Then, And..) through out multiple feature files.
For example:
Scenario: User Logs in
Given User is on the Login page
When User Logs in using 'userName' and 'password'
Then User on page containing: '/logedin/url/path'
The above test case logs in a user and I will need to use it for other Scenarios. For example, if I add a test case to update a password, the above Scenario will need to be performed before the update password scenario.
The test will need to perform the Login steps and then update password steps. From my limited knowledge, it seems like I will need to have this in the Background: step. So before my update password scenario I will have the following:
Background: User Logs in
Given User is on the Login page
When User Logs in using 'userName' and 'password'
Then User on page containing: '/logedin/url/path'
Scenario: User Updates Password
Given User is on the Manage Account page
When User clicks Update Password
And User type 'existingPassowrd' and 'newPassword'
And User clicks Update Password
Then Password is displayed as 'newPassword'
This gives me an error cucumber.runtime.DuplicateStepDefinitionException which I understand, but I keep reading that serenity-cucumber gives the the option to reuse steps, which again, I get and is a good idea.
So, How do I reuse scenarios or a scenarios' step definitions in other tests? I don't need a new method for them, I just need to call the existing method that I created in the previous scenario.
Is there a way to do this?
Can I do something like this? (or do i not even need to write out the background?)
#Steps
User user;
//This is the background in the feature file.
//Instead of creating methods, I would just reference the pre-existing ones from the other test case.
#Given("^User is on the Login page$")
#When("^User Logs in using '(.*)' and '(.*)'$")
#Then("^User on page containing: '(.*)'$")
//This is the Scenario in the feature file
#Given("^User is on the Manage Account page$")
public void user_is_on_the_manage_account_page(String expectedUrl) throws Exception {
user.is_on_page(expectedUrl);
}
#When("^User clicks Update Password$")
public void user_clicks_update_password() throws Exception {
user.click_update_password();
}
code continues
...
...
...
Found the answer...
As long as the feature file text:
Given User is on the Login page
is written the same in multiple feature files, you only need to write the "step definition" method once
#Given("^User is on the Login page$")
public void user_is_on_the_login_page() throws Exception {
user.is_on_login_page();
}
"User is on the login page" can keep getting re-written on multiple feature files, it will always use that same method user_is_on_the_login_page() and no code needs to be written on that test's step definition file.

Custom AspNetWindowsAuthProvider

Can I login only specific users with AspNetWindowsAuthProvider in ServiceStack.
I created a CustomAspNetWindowsAuthProvider and I have a table whitelist with allowed users, in the method IsAuthorized I am checking if the user exits in the table, if not exits I returned false but it's not working, any idea?
If you've created a Custom AuthProvider that overrides AspNetWindowsAuthProvider and you've override Authenticate() it still needs to call IsAuthorized(user) in your custom implementation like it's done in AspNetWindowsAuthProvider.

Get user from sharepoint group and redirect

My requirement is when someone login to site and if he belong to 'owner' group it need to redirect immediately to specific site and if he belong to member group then need to navigate/redirect to same specified site other page.
A very simple solution could be to use SPSecurityTrimmedControl. What it does is that it adds whatever is inside the control only if the specified access is fulfilled by the user.
So what you can do is that set the permissioning of the control to full control and include a simple redirect JavaScript. And just after that, outside the control, add a redirect script to other control. Something like below:
<SharePoint:SPSecurityTrimmedControl ID="SPSecurityTrimmedControl1" runat="server" AuthenticationRestrictions="AuthenticatedUsersOnly" Permissions="ManageWeb" PermissionContext="CurrentSite">
<script type='text/javascript'>javascript to redirect owners</script>
</SharePoint:SPSecurityTrimmedControl>
<script type='text/javascript'>javascript to redirect readers</script>
So if the user is an owner, the owner redirect sscript will be present on the page and if not then it will redirect to the reader's page.
Since it is in SP2010, I assume we use server side C# code instead of CSOM, which is not matured yet in SP2010.
create a static helper method like:
public static bool IsInGroup(this SPUser user, SPGroup group)
{
return user.Groups.Cast()
.Any(g => g.ID == group.ID);
}
}
verify in your code if the user belongs to certain group
SPUser user;
SPGroup group;
bool belongToGroup = user.InGroup(group);
use SPUtility.Redirect to redirect the user to any page you need.
Hope this helps somehow.

If New Document/Media uploaded in liferay by admin, user has to get message after login

I am very new to liferay. Please help me implementing the below requirement.
Using Document and media portlet in liferay, If any new document is uploaded or uploaded document is modified(Version changed) by admin user, then
How can i identify that the particular document is modified or newly uploaded as i have to show a popup message to user based upon if any new files is uploaded or modified after log on.
That is not a little change request - this required bit more development. And here is more different variants:
Simple but nonperformance variant:
With UserLocalServiceUtil you can check the last user-login date
Similarly iterate over all documents and check last modification date
Create Liferay-Portlet that shows the list of documents with modification date after last user-login date
~
Here are the steps:
Use corresponding Document Listener i.e
DlFolderListener or DlFileEntryListener. You have to use hook to
add your listner in portal.properties.
For Example, you would need to workaround below property.
value.object.listener.com.liferay.portlet.documentlibrary.model.FileEntry
= com.my.custom.MyFileEntryListener
This class would be extending BaseModelListener<FileEntry>
Override and use onAfterUpdate method to notify appropriate audience
(users).
Now this can be done by setting this notification in user
preferences.
On user Login, check corresponding user preferences for this
notification and notify user. You can use hook LoginPostAction to read user preferences for notification.
Hope this helps.
Create customfield for user. Create table with service builder to store the fileEntry Id which modified.
Create DLFileEntry Listener and write
code on FileUpdate. Add DLFileEntryID in same table created in step 1. Set
custom field true for all the user.
Create LoginPostActionHook and on Check the user's flag and fetch the FileEntryId get info of that fileEntryId and display notification with all file's information. Set customfield Flag false for particular user and remove the fileentryid from table or mark them all as read.

Logged in user can only access 1 page?

Using Orchard 1.6 Iv created a new role 'FactoryWorker'. When this user logs in from the front end I want them to be navigated to one page only.
OrchardLocal/System/ManufacturedProducts
I have set this page to be a print screen of the order details so the factory worker will know what products to get ready for ship out & they wont be able to navigate as no menu appears, but also need the other pages blocked incase the user decides to enter the URL of a page they arnt allowed access to.
This is the only page I want this particular user to be able to access(after they login), and I have added a logout button, which logs out the user and returns them to the home page.
So iv been looking through editing a role, with permissions and content etc...but this all seems to be applying to forms and content in general. where the user can access any content type etc...
So can someone advise me on how to do this?
thanks for any replies
UPDATE
I forgot to mention that this is not a content type, item or part I am talking about.
I have created my own controller & View & VM which is accessible from the dash board (using the AdminMenu, which brings the admin user to OrchardLocal/System/ManufacturedProducts)
I have looked at Orchard.ContentPermissions Feature but it only seems to allow me to 1)Grant permissions for others or 2)Grant permission for own content
any ideas?
You can use a Request Filter, (I do not know if it is the best way) :
FilterProvider – defines the filter applied to each request. Resembles the way default ASP.NET MVC action filters work with the difference that it’s not an attribute. All FilterProvider objects are injected into the request pipeline and are applied to all requests (so you need to check if the current request is suitable for your filter at the beginning of an appropriate method).
From : http://www.szmyd.com.pl/blog/most-useful-orchard-extension-points
So you could implement something like this
public class Filter : FilterProvider, IAuthorizationFilter {
private readonly IAuthenticationService _authenticationService;
public Filter(IAuthenticationService authenticationService) {
_authenticationService = authenticationService;
}
public void OnAuthorization(AuthorizationContext filterContext) {
//If route is the restricted one
if (filterContext.HttpContext.Request.Url.AbsoluteUri.Contains("OrchardLocal/System/ManufacturedProducts")) {
//Get the logged user
IUser loggedUser = _authenticationService.GetAuthenticatedUser();
if (loggedUser == null)
return filterContext.Result = new HttpUnauthorizedResult();
//Get the Roles
var roles = loggedUser.As<IUserRoles>().Roles;
if (!roles.Contains("FactoryUser")) {
//User is not authorized
return filterContext.Result = new HttpUnauthorizedResult();
}
}
}
}
Note: Untested code!
EDIT: Also you could invert the logic and check if the logged user has the role 'FactoryUser' and restrict its access to every page except the one they should see.
Your module can create a new permission (look at one of the permissions.cs files for examples), then create a role that has only that permission. Have your controller action check that permission (again, many examples found by finding usage of the permissions defined in one of the permissions.cs).
You can use the Content Permissions module. Using this module you can attach a content item permission part to a content type. This part allows you to choose which roles can see the content when you create it.

Resources