kvikende's blog

Random stuff from a Norwegian student

Login to SugarCRM with its REST API from Javascript

August 20th, 2012

Hello. I’ve been doing a summer project where I’ve developed a mobile-friendly website for SugarCRM. Only catch was that the site had to call the SugarCRM’s REST api from Javascript rather than from PHP. All examples on the web was with PHP, so I figured I should write some quick posts with Javascript examples. All code is under the MIT licence. Do as you please.

Please note that I’m using jQuery.

First example is login.

/* First get the username and password from the login fields. */
var username = $('#UsernameField').val();
var password = $('#PasswordField').val();

/* Then hash the password with md5 */
var hashedPassword = $.md5(password);

/* Prepare the "header", if you like, specifying which REST API method
 * is to be called and that we're about to use JSON.
 */
var dataToSend = {
	method : "login",
	input_type : "JSON",
	response_type : "JSON"
};

/* Prepare an object which is going to be converted into
 * JSON. You don't want to write JSON manually.
 */
var restData = {
	user_auth : {
		user_name : username,
		password : hashedPassword
	},
	application : "SugarCRM",
	name_value_list : {
		name : "language",
		value : "en_US"
	}
};
/* Convert the object to JSON with the browser's
 * built in JSON.stringify() command.
 */
dataToSend.rest_data = JSON.stringify(restData);

/* UrlToRestApi is the URL to the rest.php file somewhere in the SugarCRM instance. */
$.post(UrlToRestApi, dataToSend,
	function(data) {
		/* This is the callback method which will be run when
		 * the server responds.
		 */
		var response = $.parseJSON(data);
		/* Logical AND here. Blog is being stupid. */
		if (response.name !== undefined && response.name === "Invalid Login") {
			alert("Username and/or password is invalid.");
			return;
		}
		/* Here the login did not fail. Store the session ID sugar gives us.
		 * It will be important later.
		 */
		SugarSessionId = response.id;
	});

Please note that I’m aware that SugarCRM is “OpenCore”.

Free Software BOINC projects

August 5th, 2011

I’ve long been a fan of distributed computing and I’ve participated in several different projects over the years, everything from United Devices to Folding@home. Over the years I’ve grown fond of Free Software and I switched over to BOINC after much frustration with Folding@home’s poor Linux support; failing to give a client compatible with my distro’s glibc. At first I didn’t care much about which licenses the BOINC projects I chose to participate in used and I chose mainly on the basis of what I thought was interesting. After some thinking I finally took licensing into account.

The amount of Free Software BOINC projects is very low even though the BOINC client itself is free. Here’s a list of those I’ve found to be free:

  1. SETI@home, GPLv2
  2. Eintein@home, GPLv2
  3. Leiden Classical, LGPLv2.1
  4. The Lattice Project, some are GPLv3 it seems. Not all Free Software.
  5. AQUA@home, BSD style
  6. FreeHAL@home, GPLv3

This list was made from https://boinc.berkeley.edu/projects.php and if I’ve missed one or more, please comment.

My experiences with Debian Sqeeze and Fedora 14

January 21st, 2011

I have been using Fedora for some time on both my laptop and my desktop, and when my dad’s Windows install somehow broke I installed Fedora on his laptop as well. Only thing he complained about was Firefox because their bookmark handling is somewhat different than IE.

Desktop computer

My desktop computer ran Fedora 13 acceptably fine. I then decided to upgrade to 14 because I love new shiny stuff and stuff began to break. On every boot ABRT (Fedora’s crash detector) reported a kernel oops. When editing LaTeX documents I could get Gedit to crash by fiddling a bit in the settings. I use MSN, and Empathy related plugins would crash and the maintainers of those plugins would not respond on the bug reports.

I then decided to go for Debian Squeeze. It installed fine, but the Installer looked and felt archaic. That it only supported open or WEP encrypted wireless accesspoints shocked me. I got experimental repo installed because using a Firefox 3.5 isn’t acceptable for me. I like my stuff new and shiny regardless if it compiles on the Alpha platform. Only issue I have is that after a long while the keyring begin bugging me about being locked and I have to provide a password.

I’m pleased.

Laptop

I used Fedora but I found it slowing down over time. I had also Windows set up as a dual boot. Around Christmas I installed Debian on it. The installation was awful. I had no burnable CDs or DVDs available so I thought I could just do as I always do: Unetbootin. Sadly it failed every time. I then got very frustrated, but I began reading the manual (manuals are for wimps) where it gave clear instructions on how to do it. When I followed those everything went fine.

Being a computer I would bring to Univ I wanted to make it look less crap when booting by installing Plymouth. I could not get it to work. I gave up in the end and installed Fedora 14 on it again. This time a clean install and not upgrade from Fedora 13. It now works fine and I love it.

I also removed the Windows install and made sure no proprietary software was installed on it. Only proprietary stuff on it is some firmware but I need it for my wireless to work.

Dad’s laptop

Because dad is moving and bringing his laptop with him (which means I cannot help him physically anymore) I decided to install Debian Squeeze on his machine. I don’t think he misses much except the pretty boot on Fedora. Hopefully he won’t have any problems as I’m kind of unable to help him now. I trust you Debian guys to not break his laptop! 🙂

Comment or something if this was an interesting read in any way.

Solution to not being able to type norwegian characters in Fedora 13

June 11th, 2010

This post is in Norwegian. The head line is in English so it’ll show up when someone searches for a solution.

For de som har installert (og ikkje oppgradert til) Fedora 13 og ikkje klarer å skrive bokstavane æøå og slike teikn, så er det ein velkjend feil i Fedora 13 og som er rapportert til https://bugzilla.redhat.com/show_bug.cgi?id=596664.

Løysninga er enkel:

  • Opne opp terminalen
  • Skriv «export LANG=nn_NO.UTF-8» for nynorsk og «export LANG=nb_NO.UTF-8» for bokmÃ¥l

Dessverre må ho gjerast kvar gong maskina har blitt slegen av eller brukaren har logga ut.

Upset over Fedora

March 11th, 2010

I’m a Fedora user. I currently run Fedora 12 on both my laptop which I use to do university stuff (mostly coding for assignments) and on my desktop stationary computer. I use it because it is close to upstream and it has a lot of new shiny stuff every six months.

What I’m upset about is that Fedora has to follow US export regulations. I know I really should be upset over USA for having that export regulation however we live in a interconnected world. I can’t see why Fedora doesn’t just go somewhere where those idiotic export regulations don’t apply.

I’m seriously considering moving to Debian unstable. Never used it before though. Don’t really know how much it will break.

RL and GNOME translation stuff

February 27th, 2010

I have gotten antibiotics to get rid of my pneumonia. My girl friend has winter vacation and she and her family have went to Italy for a week. That means I have time to finally take the theory exam necessary to get a driver’s license. Ah. The freedom I will have when I can drive and not be completely dependent on public transport.

I am also going to try to get some GNOME translation work done. There are still much work needed to get GNOME 2.30 as much translated as GNOME 2.28 and I doubt we will make it. A bit sad but we are really low on man power and all of us (I think) are doing it on our free time.

Hopefully I’ll get some of the low hanging fruits done during the weekend. Let’s see.