I have added a script to send mail whenever a site is created. How to restrict the email notification if the site created is a private site. Here is my java script
var mail = actions.create("mail");
var node = people.getGroup("GROUP_EMAIL_CONTRIBUTORS");
if(node){
var members = people.getMembers(node);
}
mail.parameters.from = "Administrator#community.com"
mail.parameters.subject=" A new site called " + document.properties.name+" is created";
mail.parameters.text="Click http://sameer_w7:8080/share/page/site/" + document.properties.name + "/dashboard" + " to join the site";
for(var i=0;i<members.length;i++)
{
mail.parameters.to = members[i].properties.email;
//execute action against a document
mail.execute(document);
}
You can get the siteVisibility state of a site.
Take a look at the SiteService Wiki page.
Something like this should work:
if (document.properties["st:siteVisibility"] != "PRIVATE"){
<your email action here>
}
Be sure you have selected type is st:site in your rule, otherwise add an extra check on that.
Related
I have created one custom Dashlet, and added it to site dashboard.
But now my requirement is that, I want to display that custom only for site manager and i want to hide it for all other users.
Can anyone help me with this? How can hide custom Dashlet for all consumers and collaborators.
Thanks in advance.
In your controller javascript (aka .get.js file) add an extra remote.call to get the groups of the current user like:
var groupResult = remote.call("/api/people/" + stringUtils.urlEncode(user.name) + "?groups=true");
Use the result and eval it, then send it to your freemarker dashlet.
--- Update ---
You can also take a look at the default share-header webscript.
Take a look at the file org\alfresco\share\imports\share-header.lib.js
The snippet:
// Call the repository to see if the user is site manager or not
var userIsSiteManager = false,
userIsMember = false;
json = remote.call("/api/sites/" + page.url.templateArgs.site + "/memberships/" + encodeURIComponent(user.name));
if (json.status == 200)
{
var obj = eval('(' + json + ')');
if (obj)
{
userIsMember = true;
userIsSiteManager = obj.role == "SiteManager";
}
}
siteData = {};
siteData.profile = profile;
siteData.userIsSiteManager = userIsSiteManager;
siteData.userIsMember = userIsMember;
// Store this in the model to allow for repeat calls to the function (and therefore
// prevent multiple REST calls to the Repository)...
// It also needs to be set in the model as the "userIsSiteManager" is required by the template...
model.siteData = siteData;
so use this in an if statement in freemarker
I'm building a registration component on a Sitecore Site (Sitecore 7.0 ) and while the users are being created, none of the custom profile or role is being created. There are no errors in the logs. The user that is created has the correct user name and domain, but does not have the custom profile and lacks the full name, email address, role and additional custom fields. Has anyone encountered any related difficulties achieving this?
N.b. using email address as username if that will make any difference. I've updated the config to allow this. I've also added some logging underneath, which all outputs the correct information.
Here's a sample of the code:
try
{
if (!User.Exists(userEntity.EmailAddress))
{
var user = Membership.CreateUser(CreateUserName(userEntity), userEntity.Password,
userEntity.EmailAddress);
User scUser = User.FromName(userEntity.EmailAddress, true);
if (Role.Exists(Constants.Roles.ExampleRole) && !scUser.IsInRole(Constants.Roles.ExampleRole))
{
Roles.AddUserToRole(userEntity.EmailAddress, Constants.Roles.ExampleRole);
}
if (scUser != null)
{
using (new Sitecore.SecurityModel.SecurityDisabler())
{
scUser.Profile.FullName = userEntity.FirstName + " " + userEntity.LastName;
scUser.Profile.ProfileItemId = Constants.CustomUserProfile.ToString();
scUser.Profile.SetCustomProperty(UserFields.FirstName, userEntity.FirstName);
scUser.Profile.SetCustomProperty(UserFields.LastName, userEntity.LastName);
scUser.Profile.SetCustomProperty(UserFields.EmailAddress, userEntity.EmailAddress);
scUser.Profile.SetCustomProperty(UserFields.TelephoneNumber, userEntity.TelephoneNumber);
scUser.Profile.SetCustomProperty(UserFields.CompanyName, userEntity.CompanyName);
scUser.Profile.SetCustomProperty(UserFields.Sector, userEntity.Sector);
scUser.Profile.SetCustomProperty(UserFields.AddressLine1, userEntity.AddressLine1);
scUser.Profile.SetCustomProperty(UserFields.AddressLine2, userEntity.AddressLine2);
scUser.Profile.SetCustomProperty(UserFields.City, userEntity.City);
scUser.Profile.SetCustomProperty(UserFields.PostCode, userEntity.Postcode);
scUser.Profile.SetCustomProperty(UserFields.State, userEntity.State);
scUser.Profile.SetCustomProperty(UserFields.Country, CountryUtility.GetCountryNameById(userEntity.SelectedCountryId));
scUser.Profile.Save();
result = true;
}
Membership.UpdateUser(user);
Log.Info(scUser.Profile.FullName, new object());
Log.Info(scUser.Profile.ProfileItemId, new object());
Log.Info(scUser.Profile.GetCustomProperty(UserFields.FirstName), new object());
Log.Info(scUser.Profile.GetCustomProperty(UserFields.City), new object());
Log.Info(scUser.Profile.GetCustomProperty(UserFields.Country), new object());
Log.Info(scUser.IsInRole(Constants.Roles.ExampleRole) ? "true" : "false", new object());
}
}
else
{
throw new Exception(Nodes.Dictionary.Fields[DictionaryFields.RegistrationForm.UsernameExists].Value);
}
}
catch (Exception exception)
{
Log.Error(exception.Message, "RegistrationController");
}
I think you need to use the fully qualified user name when loading the user from Sitecore, like this (assuming extranet domain):
User scUser = User.FromName("extranet\\" + userEntity.EmailAddress, true);
The reason everything seems to work in your code is because you get a user back from User.FromName(...) wether the user actually exists or not.
I am developing a website in C#, using the Facebook API and getting logged in user's friend list. I bind this list in a Datalist with checkbox, friends picture, Name and UserID.
When I check some checkboxes and click on a button, I want to send some sort of invite to the checked friends. I want to send the invite via a private message, notification or any other solution (but not on the user's wall). Is this possible?
I have checked all posts ,which are already in Stackoverflow.
And also checked this one http://www.fbrell.com/xfbml/fb:server-fbml-multi-friend-selector
What you are looking for is called "App-generated Requests". These are requests that are sent from inside your application without needing your users to see or act on the requests dialog.
The following code is taken from the Facebook documentation -
https://developers.facebook.com/docs/channels/#requests
<?php
$app_id = YOUR_APP_ID;
$app_secret = YOUR_APP_SECRET;
$token_url = "https://graph.facebook.com/oauth/access_token?" .
"client_id=" . $app_id .
"&client_secret=" . $app_secret .
"&grant_type=client_credentials";
$app_access_token = file_get_contents($token_url);
$user_id = THE_CURRENT_USER_ID;
$apprequest_url ="https://graph.facebook.com/" .
$user_id .
"/apprequests?message='INSERT_UT8_STRING_MSG'" .
"&data='INSERT_STRING_DATA'&" .
$app_access_token . "&method=post";
$result = file_get_contents($apprequest_url);
echo("App Request sent?", $result);
?>
Once sent, new requests a user has received are visible as a counter
on your application's bookmark and it also increments the counter next
to the appropriate Dashboard.
The code is in PHP but it is using the very generic file_get_contents() method. You can use this logic with any language capable of making HTTP requests.
This code will post on your friend's wall ,whatever you want to post:
for (Int32 i = 1; i < DLFbFriend.Items.Count; i++){
CheckBox Chkbox =(CheckBox)DLFbFriend.Items[i].FindControl("chkUserID");
if (Chkbox.Checked)
{
HiddenField hdfUserId = (HiddenField)DLFbFriend.Items[i].FindControl("hdfUserID");
string d = hdfUserId.Value;//friend's facebook generated id,whom you want to invite
String link = "what ever you want to post";
string url1 = "https://graph.facebook.com/" + d + "/feed?access_token=" + Request.QueryString["access_token"] + "&link=" + link + "&from=" + Session["Pinny_USER"].ToString().Split('~')[0] + "&name=Register with Pinny&message=Your friend invites you&picture=http://168.144.124.15/images/logoPinny.jpeg";
HttpWebRequest request1 = (HttpWebRequest)WebRequest.Create(url1);
request1.Method = "POST";
// execute the request
HttpWebResponse response1 = (HttpWebResponse)request1.GetResponse();
// we will read data via the response stream
System.IO.Stream ReceiveStream1 = response1.GetResponseStream();
StreamReader readStream1 = new StreamReader(ReceiveStream1);
string json1 = readStream1.ReadToEnd();
countinvited += 1;
}
}
I already have code which works fine, but for security reason I want to make other way of Auth.
In this case, user writes his username and password, but I want to make like "Allow demo.com to access your information's" click button.
How to change this code:
//Provide Login Information
Google.GData.Client.RequestSettings rsLoginInfo = new Google.GData.Client
.RequestSettings("", txtEmail.Text, txtPassword.Text);
rsLoginInfo.AutoPaging = true;
// Fetch contacts and dislay them in ListBox
Google.Contacts.ContactsRequest cRequest = new ContactsRequest(rsLoginInfo);
Google.GData.Client.Feed<Google.Contacts.Contact> feedContacts = cRequest
.GetContacts();
foreach (Google.Contacts.Contact gmailAddresses in feedContacts.Entries) {
Console.WriteLine("\t" + gmailAddresses.Title);
lstContacts.Items.Add(gmailAddresses.Title);
foreach (EMail emailId in gmailAddresses.Emails) {
Console.WriteLine("\t" + emailId.Address);
lstContacts.Items.Add(" " + emailId.Address);
}
}
It seems like you're trying to do 3-Legged OAuth. .NET samples for performing 3-Legged OAuth 1.0a are documented here:
http://code.google.com/apis/gdata/docs/auth/oauth.html#Examples
I am have made one web application in asp.net.In my project Authentication was done by matching the username and password in database.But now client ask me for the auto login in application with the help Of Active Directory authentication. Client ask suggest me to use the Email Id of user in AD for the authentication.
I tried to fetch the records in the AD, I could fetch the Fullname of user but I couldn't get the Email id,
I tried the code:
System.Security.Principal.WindowsIdentity wi = System.Security.Principal.WindowsIdentity.GetCurrent();
string[] a = Context.User.Identity.Name.Split('\\');
System.DirectoryServices.DirectoryEntry ADEntry = new System.DirectoryServices.DirectoryEntry("WinNT://" + a[0] + "/" + a[1]);
string Name = ADEntry.Properties["FullName"].Value.ToString();
Further more I Use DirectorySearcher but it genterates Error that Coulnot search the record in the client server..
I had the exact same situation while making a portal for a company.
If they dont want you to get into their AD then what you can do is to request for the NTLogins of the people who will be given access to the portal. make a simple table which have their NTLogin and simply authenticate using the system from which the portal is being accessed.
Check out the sample code i used.
// Checking if the user opening this page is listed in the allowed user list against their NT login.
String sUser = Request.ServerVariables["LOGON_USER"].ToLower();
sUser = sUser.Replace("wt\\", "");
//Authentication using a custom auth method.
DatabaseOperations authenticateUser = new DatabaseOperations();
if (!authenticateUser.authenticate(sUser))
{
//unauthorized users will be redirected to access denied page.
Server.Transfer("AccessDenied.aspx", true);
}
And making sure that you have authentication mode to windows in your web.config file
<authentication mode="Windows"></authentication>
Hope this helps.
For reading AD data, i use this class. It is setup for our AD, but basically you can just pass in all the "fields" you want to find, in the params.
But you need to know what field holds the email address. Sysinternals made a pretty good tool for browsing AD, to figure out what you are looking for, called ADExplorer.
But I don't understand why you need to look in the AD? Can you not assume that the user is already authenticated, if they are on the network, and then rely on the windows identity?
public static Hashtable GetAttributes(string initials, params string[] Attribute)
{
DirectoryEntry directoryEntry = new DirectoryEntry("LDAP://ADNAME");
DirectorySearcher ADSearcher = new DirectorySearcher(directoryEntry);
ADSearcher.Filter = "(sAMAccountName=" + initials + ")";
foreach (string para in Attribute)
{
ADSearcher.PropertiesToLoad.Add(para);
}
SearchResult adSearchResult = ADSearcher.FindOne();
Hashtable hshReturns = new Hashtable();
foreach (string para in Attribute)
{
string strReturn = "";
if (adSearchResult.Properties[para].Count == 0)
strReturn = "";
else
strReturn = ((ResultPropertyValueCollection)adSearchResult.Properties[para])[0].ToString();
hshReturns.Add(para, strReturn);
}
return hshReturns;
}