I have built my site based around the user management that comes with the starter site template. This works very well, except i need to modify it slightly for my use case. Let me explain:
Currently, when a new user registers, the user is created in the database, but does not let users access any pages that are secured using "WebSecurity.RequireAuthenticatedUser();" until they open and click a confirmation email....
I want to allow users access to certain parts of my site before they confirm their email, is this possible?
Should i be using a different method to WebSecurity.RequireAuthenticatedUser()?
Should i be removing the "requireEmailConfirmation" switch when creating the user??
Currently, it looks like this:
try {
bool requireEmailConfirmation = !WebMail.SmtpServer.IsEmpty();
var token = WebSecurity.CreateAccount(email, password, requireEmailConfirmation);
if (requireEmailConfirmation) {
var hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
var confirmationUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/owner/confirm?confirmationCode=" + HttpUtility.UrlEncode(token));
var details = "X-MC-MergeVars: {\"FIRSTNAME\": \"" + firstname + "\", \"LASTNAME\": \"" + lastname + "\", \"CONFIRMADDRESS\": \"" + confirmationUrl + "\"}";
var header = new[]{"X-MC-Template:registertemplate", "Reply-To:noreply#stayinflorida.co.uk", details};
WebMail.Send(
to: email,
subject: "Please confirm your account",
body: "Your confirmation code is: " + token + ". Visit " + confirmationUrl + " to activate your account.",
additionalHeaders: header
);
}
if (requireEmailConfirmation) {
// Thank the user for registering and let them know an email is on its way
Response.Redirect("~/owner/thanks");
} else {
// Navigate back to the homepage and exit
WebSecurity.Login(email, password);
Response.Redirect("~/");
}
} catch (System.Web.Security.MembershipCreateUserException e) {
ModelState.AddFormError(e.Message);
}
for pages they must be registered to use
This goes at the top
#{
if (!WebSecurity.IsAuthenticated) {
Response.Redirect("~/Account/Login?returnUrl="
+ "~/AllRaces.cshtml");
}
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Upcoming";
}
For pages anyone can look at
this goes at the top
#{
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Contact";
}
Related
I have a document library on SharePoint online with lots of columns for metadata. These columns won't fit in a single view on screen, so I want the users to first view the properties of the file before downloading them.
Is there a way to change the behavior of the SharePoint library ensure that the user views the file properties first when they click on the filename?
PS: I understand I could have used lists, but after loading about 10000 documents, I have decided to use it as a last resort. Thank you.
Custom the LinkFilename field by CSR.
Sample code:
(function () {
'use strict';
var CustomWidthCtx = {};
/**
* Initialization
*/
function init() {
CustomWidthCtx.Templates = {};
CustomWidthCtx.Templates.Fields = {
'LinkFilename': {
'View': customDisplay
}
};
// Register the custom template
SPClientTemplates.TemplateManager.RegisterTemplateOverrides(CustomWidthCtx);
}
/**
* Rendering template
*/
function customDisplay(ctx) {
var currentVal = '';
//from the context get the current item and it's value
if (ctx != null && ctx.CurrentItem != null)
currentVal = ctx.CurrentItem[ctx.CurrentFieldSchema.Name];
var el = "<div class='ms-vb itx' id='" + ctx.CurrentItem.ID + "' app='' ctxname='ctx37'><a title='" + ctx.CurrentItem._ShortcutUrl + "' class='ms-listlink ms-draggable' aria-label='Shortcut file' onfocus='OnLink(this)' href='/Doc4/Forms/EditForm.aspx?ID=" + ctx.CurrentItem.ID + "' target='_blank' DragId='17'>" + ctx.CurrentItem.FileLeafRef + "</a></div>";
// Render the HTML5 file input in place of the OOTB
return el;
}
// Run our intiialization
init();
})();
I have a form which sends by post method registration.jsp file, first saved in the database and then must open a "command.sh":
<%# page import ="java.sql.*,java.io.*"%>
<%
String user = request.getParameter("uname");
String pwd = request.getParameter("pass");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/jsp",
"root", "");
Statement st = con.createStatement();
int i = st.executeUpdate("insert into members(uname, pass, regdate) values ('" + user + "','" + pwd + "', CURDATE())");
Process p=Runtime.getRuntime().exec("./command.sh "+user+pwd);
if (i > 0) {
response.sendRedirect("welcome.jsp");
} else {
response.sendRedirect("index.jsp");
}
I am using the following code, but when I run it I get an error:
Error
Files
Yes save in the database.
I also do not know how to create a Unix user by receiving the data I sent from the jsp.
Please Help Me
Try using ServletContext.getRealPath(), for example:
String fullPath = application.getRealPath("command.sh");
String[] cmd = { fullPath + " " + user + pwd };
Process p = Runtime.getRuntime().exec(cmd);
I am editing online available snooze script for gmail, where i would like to bring back an email unread, in inbox and on top of the list. I am able to make it unread, and bring back to inbox based on the available script, but to bring on top of the inbox, i am forwarding the email to myself. By this, I am able to get the email thread on top of the list, but when an email which is snoozed has an attachment, it forwards the email with attachment. I have tons of emails, and have limited available space. Hence i am ending up using extra storage for duplicate attachment which is unneeded.
I would like to forward the email, without attachment. Below is my current script:
var firstThread = page[i];
var giattachment = null;
var sub = firstThread.getFirstMessageSubject();
var newsub = "Reminder: " + firstThread.getFirstMessageSubject() + " : ";
var id = newsub + firstThread.getPermalink();
var messages = firstThread.getMessages();
var totalThreadCount= firstThread.getMessageCount();
for (var j = 0; j < messages.length; j++) {
var forwardlength=messages.length-1;
if(j == forwardlength) {
if (MARK_UNREAD) {
messages[j].markUnread();
}
messages[j].forward(userEmail,{subject: newsub, from:userEmail, name: EmailFrom, body: newbody, attachments:giattachment});
}
}
Inspite of this, the email gets forwarded with an attachment. Please advise..
Thanks in advance
To selectively forward messages, use filters to create rules that forward in response to message attributes or content.
You can filter messages by properties such as the sender, subject date, size, and message contents. Any query using Gmail's advanced search syntax can also be used in a filter. Try to set criteria.hasAttachment=true to false.
For more information, follow this link: https://developers.google.com/gmail/api/v1/reference/users/settings/filters
You can't forward using Class GmailMessage because it forces you to forward the original attachments. While unforunately undocumented, its advanced parameter attachments can only add new attachments.
However, you can forward by creating a new message using Class MailApp instead, in your case it would be:
var from, firstThread = page[i];
var sub = firstThread.getFirstMessageSubject();
var newsub = "Reminder: " + firstThread.getFirstMessageSubject() + " : ";
var id = newsub + firstThread.getPermalink();
var messages = firstThread.getMessages();
var totalThreadCount= firstThread.getMessageCount();
for (var j = 0; j < messages.length; j++) {
var forwardlength=messages.length-1;
if(j == forwardlength) {
if (MARK_UNREAD) {
messages[j].markUnread();
}
from = message.getHeader('From');
if (from.indexOf(' <') > -1)
from = from.substring(0, from.indexOf(' <'));
else
from = '';
MailApp.sendEmail(userEmail, newsub, '', {htmlBody: messages[j].getBody(), name: from, replyTo: message[j].getFrom()});
}
}
Changes:
Removed your var giattachment = null;
Replaced your messages[j].forward with MailApp.sendEmail
Used messages[j].getBody() to simulate the original body
Added the original sender's name as the "sender's" name
Added the original sender's address as reply-to
The last 2 points mean the forwarded message will arrive from "someone else's name" <your#address> which for most recipients will appear like a true forward.
I'm getting this to work if I choose a specific list to add the action to. Is there an easy way to enable this custom action on all document libraries in the whole sitecollection?
Code sample:
function createUserCustomActionList() {
var cmd = "<CommandUIExtension><CommandUIDefinitions><CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">" +
"<Button Id=\"DiaryAction.Button\" TemplateAlias=\"o1\" Command=\"DiaryCommand\" CommandType=\"General\" LabelText=\"Dela flera\" Image32by32=\"https://eolusvind.sharepoint.com/sites/intranet/_layouts/15/1033/Images/formatmap32x32.png?rev=23\"" +
" Image32by32Top=\"-271\" Image32by32Left=\"-109\" />" +
"</CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers>" +
"<CommandUIHandler Command =\"DiaryCommand\" CommandAction=\"javascript:alert('Hej');\" EnabledScript=\"javascript:SP.ListOperation.Selection.getSelectedItems().length > 1;\" />" +
"</CommandUIHandlers></CommandUIExtension>";
var ctx = new SP.ClientContext.get_current();
var list = ctx.get_web().get_lists().getByTitle('Dokument');
var uca = list.get_userCustomActions();
var oUserCustomAction = uca.add();
oUserCustomAction.set_location('CommandUI.Ribbon.ListView');
oUserCustomAction.set_commandUIExtension(cmd);
oUserCustomAction.set_sequence(100);
oUserCustomAction.set_title('Dela flera');
oUserCustomAction.update();
ctx.load(list, 'Title' ,'UserCustomActions');
ctx.executeQueryAsync(function () {
alert('Custom action created for ' + list.get_title())
}, function (sender, args) {
alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
});
}
I would suggest the following approach for registering custom button in Documents libraries across site collection:
use RegistrationType set to 2(ContentType) and RegistrationId set to 0x0101 (for Document content type) to register custom action via content type
use site scope user custom action to apply changes across all site
collection
Example
var cmd = "<CommandUIExtension>" +
"<CommandUIDefinitions>" +
"<CommandUIDefinition Location=\"Ribbon.Documents.Manage.Controls._children\">" +
"<Button Id=\"ClickAction.Button\" TemplateAlias=\"o1\" Command=\"ViewCustomPropertiesCommand\" CommandType=\"General\" LabelText=\"View Custom Properties\" Image32by32=\"/_layouts/15/1033/Images/formatmap32x32.png?rev=23\" Image32by32Top=\"-1\" Image32by32Left=\"-171\" />" +
"</CommandUIDefinition></CommandUIDefinitions><CommandUIHandlers>" +
"<CommandUIHandler Command =\"ViewCustomPropertiesCommand\" CommandAction=\"javascript:console.log('View Custom Properties');\" EnabledScript=\"javascript:SP.ListOperation.Selection.getSelectedItems().length > 0;\" />" +
"</CommandUIHandlers>" +
"</CommandUIExtension>";
var ctx = new SP.ClientContext.get_current();
var customAction = ctx.get_site().get_userCustomActions().add(); //1. apply via site scope user custom action
customAction.set_location('CommandUI.Ribbon.ListView');
customAction.set_commandUIExtension(cmd);
customAction.set_sequence(112);
customAction.set_registrationType(2); //2.set to ContentType
customAction.set_registrationId("0x0101"); //2.set Document content type
//customAction.set_title('Document custom button');
customAction.update();
ctx.executeQueryAsync(function () {
console.log('Button has been registered');
}, function (sender, args) {
console.log('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
});
I'm trying to get users not in the jira-users group with email addresses not equal to: email#email.com. I can get the users not in the jira-users group(see below) but not sure how to complete the if statement to show "users email address not equal to email#email.com. I tried user.getEmail but couldn't get that to work. Would someone be able to make a suggestion with this?
Thanks.
for ( user in crowdService.search(query) ) {
if (!crowdService.isUserMemberOfGroup(user.getName(), "jira-users")) {
body = body + user.getName() + "\n"
}
}
The User object implementation depends on your particular Atlassian setup.
Try calling user.getEmailAddress():
for ( user in crowdService.search(query) ) {
if (!crowdService.isUserMemberOfGroup(user.getName(), "jira-users")
&& !user.getEmailAddress().equals("email#email.com")) {
body = body + user.getName() + "\n"
}
}