Go App is my the first test application using Go lang

Go page sources

package app

import (
    "github.com/garyburd/twister/server"
    "github.com/garyburd/twister/web"
    "text/template"
)

var (
  page *template.Template
)

func index(request *web.Request) {
  page.Execute(
    request.Respond(web.StatusOK, web.HeaderContentType, "text/html; charset=utf-8"),
    request.URL.Host)
}

func main() {
  page = template.Must(template.New("index").Parse(body))

  server.Run(":8080",
    web.NewRouter().
      Register("/", "GET", index))
}

const body = `
<html>
  <head>
    <title>Developed using Go :)</title>
  </head>
  <body>
    <h1>I made this page using Go language</h1>
  </body>
</html> `
1 note

Cross domain requests jQuery $.getJSON and nodejs. in the server side.

Hi, everyone.

In my current project for google chrome webstore I am using nodejs as server for saving high scores of the game. And in the client side - jQuery for receiving high scores. But I found one problem connecting with jsonp format.

When I tried to send request to the nodejs url(http://oivoodoo.no.de/json) for getting the json data with scores I saw issue(in chrome) connecting with cross domain requests. My nodejs server was returning data in jsonp format(Content Type - application/javascript).

At first time I write the next following code for jquery:

$.getJSON('http://oivoodoo.no.de/json', function(data) {
  var html = "";
  $.each(data, function(i, o) {
    html += "<li>" + o.username + ": " + o.scores + "</li>";
  });
  $("#scores_table").html(html);
});
app.get('/:format?', function(req, res) {
  Score.find({}, function(err, scores) {
    switch(req.params.format) {
      case 'json':
        res.header("Access-Control-Allow-Origin", "*");
        res.send(scores.map(function(s){
            return s.toObject();
        }));
      break;
      default:
        res.render('index.jade', {
            locals: { scores: scores }
        });
    }
  });
});

As you can see I’ve added ‘res.header(“Access-Control-Allow-Origin”, “*”);' this line to the json request. And it works!!!

3 notes

Custom sign out SharePoint page for FBA user.

Hi, everyone!

In my latest project we are using FBA users for our portal. And in the prototype of the master page such as generic web page we have login control with username, password boxes and ‘sing in’ button. If you will use for login just general sign in control of ASP .NET we will lose with authentication, exception will appear in the page. For fixing this problem we have to use SPClaimsUtility.

For example:

protected void OnAuthenticate(object sender, AuthenticateEventArgs e)
{
    e.Authenticated = SPClaimsUtility.AuthenticateFormsUser(Request.Url, signIn.UserName, signIn.Password);
}

But for sign out we have to create custom page for logout current user from portal. In all forums you can find information that’s you can use default signout.aspx page from 14 hive. But it’s true if you created custom login page inherited from SharePoint SignInPage. Default page is working incorrectly, it made sign out but doesn’t remove cookies from browser and the next page what you will see after signout, it will ‘Exception … ArgumentException … encodedValue’.

Insert the next following code to the page for clearing sign out.

protected override void OnLoad(EventArgs e)
{
	base.OnLoad(e);

	FormsAuthentication.SignOut();
	var authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
        // Clear .ASPAUTH cookie key.
	if (authCookie != null)
	{
		var myCookie = new HttpCookie(authCookie.Name) {Expires = DateTime.Now.AddDays(-1)};
		Response.Cookies.Add(myCookie);
	}

	SPIisSettings iisSettingsWithFallback = Site.WebApplication.GetIisSettingsWithFallback(Site.Zone);
	if (iisSettingsWithFallback.UseClaimsAuthentication)
	{
		FederatedAuthentication.SessionAuthenticationModule.SignOut();
                // Clear FedAuth Cookie key
		FederatedAuthentication.SessionAuthenticationModule.DeleteSessionTokenCookie();
	}


	SPUtility.Redirect(Web.ServerRelativeUrl, SPRedirectFlags.Default, Context);
}

That’s all what you need to add to the custom sign out page.

1 note

My new computer! The next step: Buy monitor :)

0 notes

PowerShell script for testing email sending via SharePoint API

write-host “`nLoad sharepoint library`n”
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")

write-host “`nOpen sharepoint site`n”
$site = new-object Microsoft.SharePoint.SPSite("http://localhost:42234")

write-host “`nOpen sharepoint root web`n”
$web = $site.RootWeb

write-host “`nTry to send email`n”
[Microsoft.SharePoint.Utilities.SPUtility]::SendEmail($web, $true, $true, "email@test.com", "test", "test body")

write-host “`Completed`n”

1 note

Install RMagick to Ubuntu

sudo apt-get install imagemagick
sudo apt-get install libmagick9-dev
sudo gem install rmagick
0 notes