Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
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...
commit fa211295b1d4fee0862d4c379cb78775c5622c2f 1 parent 671272a
@Joony authored
View
BIN  Mnesia.nitrogen@localhost/DECISION_TAB.LOG
Binary file not shown
View
BIN  Mnesia.nitrogen@localhost/LATEST.LOG
Binary file not shown
View
BIN  Mnesia.nitrogen@localhost/users.DCD
Binary file not shown
View
BIN  Mnesia.nitrogen@localhost/verification_codes.DCD
Binary file not shown
View
BIN  ebin/db_users.beam
Binary file not shown
View
BIN  ebin/string_utils.beam
Binary file not shown
View
3  src/db_users.erl
@@ -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
12 src/email_utils.erl
@@ -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
10 src/string_utils.erl
@@ -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
13 start.sh
@@ -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"
View
25 wwwroot/productTemplate.html
@@ -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>
Please sign in to comment.
Something went wrong with that request. Please try again.