Permalink
Browse files

Added a string to MD5 to string function in the string_utils module

Added some functionality to the validation email
  • Loading branch information...
Joony committed May 20, 2009
1 parent 671272a commit fa211295b1d4fee0862d4c379cb78775c5622c2f
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
View
Binary file not shown.
View
Binary file not shown.
View
@@ -37,6 +37,8 @@ init() ->
add_user(Username, EmailAddress, Password) ->
<<PasswordDigest:160>> = crypto:sha(Password),
Code = string_utils:generate_random_string(32),
+ <<CodeDigest:128>> = crypto:md5(Code),
+ io:format("CodeDigest: ~w~n", [CodeDigest]),
UsersRow = #users { username=Username, email_address=EmailAddress, password=PasswordDigest, date_joined=erlang:universaltime() },
VerificationCodeRow = #verification_codes { email_address=EmailAddress, verification_code=Code },
F = fun() ->
@@ -47,6 +49,7 @@ add_user(Username, EmailAddress, Password) ->
{atomic, Val} ->
case validate_user(Username, Password) of
{valid, _ID} ->
+ email_utils:send_email_verification_code(EmailAddress, CodeDigest),
ok;
{aborted, Reason} ->
io:format("Failed to login after registration. Reason: ~s~n", [Reason]),
View
@@ -14,16 +14,24 @@
%%
%% email_utils.erl
%%
-%% This module provides basic functions for interacting with the database.
+%% This module provides basic functions for interacting with the whichever email application you choose.
%%
-module(email_utils).
-include("wf.inc").
-include("config.inc").
--export([send/3, send_email_verification_code/2]).
+-export([send/3, send_email_verification_code/2, test/0]).
send(To, Subject, Body) ->
esmtp:send(esmtp_mime:msg("<" ++ To ++ ">","<jonathan.mcallister@gmail.com>", Subject, Body)).
+test() ->
+ EmailAddress = "jonathan.mcallister@gmail.com",
+ Code = string_utils:generate_random_string(32),
+ CodeDigest = string_utils:md5_hex(Code),
+ email_utils:send_email_verification_code(EmailAddress, CodeDigest).
+
send_email_verification_code(To, VerificationCode) ->
+ %%io:format("Code: ~w~n", [VerificationCode]),
esmtp:send(esmtp_mime:msg("<" ++ To ++ ">","<jonathan.mcallister@gmail.com>", "User Login in Erlang Example - Action required - Please verify your email address", "To verify your email address, click the link below.<br /><br /><a href=\"http://127.0.0.1:8000/web/user/verify/email/?key=" ++ VerificationCode ++ "\">Confirm you email address now.</a>" )).
+
View
@@ -20,7 +20,15 @@
%%
-module(string_utils).
--export([generate_random_string/1]).
+-export([generate_random_string/1, md5_hex/1]).
generate_random_string(Length) ->
lists:flatten(lists:foldl(fun(X,AccIn) -> [random:uniform(90) + 32|AccIn] end, [], lists:seq(1,Length))).
+
+md5_hex(S) ->
+ [hex(N) || <<N:4>> <= erlang:md5(S)].
+
+hex(N) when N < 10 ->
+ $0+N;
+hex(N) when N >= 10, N < 16 ->
+ $a+(N-10).
View
@@ -3,8 +3,11 @@ cd `dirname $0`
echo Starting Nitrogen.
erl \
- -name nitrogen@localhost \
- -pa ./ebin -pa ./include \
- -s make all \
- -eval "application:start(user_login)" \
- -eval "db_utils:start()"
+ -name nitrogen@localhost \
+ -pa ./ebin -pa ./include \
+ -s make all \
+ -eval "application:start(user_login)" \
+ -eval "application:load(esmtp)" \
+ -eval "application:start(esmtp)" \
+ -eval "db_utils:start()" \
+ -config "/opt/local/lib/erlang/releases/R12B/start.config"
@@ -1,25 +0,0 @@
-<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
-<html xmlns="http://www.w3.org/1999/xhtml">
-<head>
-<title>[[[page:title()]]]</title>
-<script src='/nitrogen/jquery.js' type='text/javascript' charset='utf-8'></script>
-<script src='/nitrogen/jquery-ui.js' type='text/javascript' charset='utf-8'></script>
-<script src='/nitrogen/livevalidation.js' type='text/javascript' charset='utf-8'></script>
-<script src='/nitrogen/nitrogen.js' type='text/javascript' charset='utf-8'></script>
-<link rel="stylesheet" href="/nitrogen/jquery-ui/jquery-ui.css" type="text/css" media="screen" charset="utf-8">
-<link rel="stylesheet" href="/nitrogen/elements.css" type="text/css" media="screen" charset="utf-8">
-</head>
-
-<body>
-
-<h1>[[[page:title()]]]</h1>
-
-[[[element_flash:render()]]]
-
-[[[page:body()]]]
-
-<script>
-[[[script]]]
-</script>
-</body>
-</html>

0 comments on commit fa21129

Please sign in to comment.