Hai,
This is my task
Example:when we upload our resume to naukri.com we get mails some companys regarding job openings
so at the bottom we see a link if you want to unscribe please click the link button
so actually this is my task when customer doesnt want to receive mails from our product if he wants to unscribe when he clicks the link button he has to unsubscribe from our website
plz help me what logic i have to write which services i have to use plz help me
Thanks,
Karthik
Loading
Zoran HorvatPosted Jul 26, 2011, 5:36 AM
Now whenever your customer subscribes to mailing list, you update his customer record in your database and store Token there. Token should be a relatively long string which is randomly generated and unique.
Unsubscribing page then finds customer with Token found in URL and updates his customer record in the dabase to set Token to NULL.
With this solution, only those customers having non-NULL Token field are actually subscribed to the mailing list. All that have NULL value are not subscribed.
Zoran
karthik parchaPosted Jul 27, 2011, 5:54 AM
thanks
karthik
Anil KumarPosted Jul 27, 2011, 2:40 AM
karthik parchaPosted Jul 26, 2011, 10:11 AM
Zoran HorvatPosted Jul 26, 2011, 6:59 AM
Thanks,
Zoran
karthik parchaPosted Jul 26, 2011, 6:56 AM
Zoran HorvatPosted Jul 26, 2011, 6:28 AM
Zoran
karthik parchaPosted Jul 26, 2011, 6:24 AM
thanq awesome explanation
Now that this is done, remaining length - sb.Length characters are completely randomly generated:
while (sb.Length < length)
sb.Append((char)(rnd.Next(26) + 'A'));
can u explain this line
Zoran HorvatPosted Jul 26, 2011, 6:19 AM
string ts = DateTime.UtcNow.ToString("yyyyMMddHHmmssffff");
This would produce output:
201107261016464723
, which is year 2011, month 07, day 26, hour 10, minute 16, second 46 and part of the second 4723
Now this string, which consists of digits, is converted to letters so that 0 becomes A, 1 becomes B, ..., 9 becomes I:
for (int i = 0; i < ts.Length; i++)
sb.Append((char)(ts[i] - '0' + 'A'));
Now that this is done, remaining length - sb.Length characters are completely randomly generated:
while (sb.Length < length)
sb.Append((char)(rnd.Next(26) + 'A'));
In this way you get string of required length which consists of current UTC timestamp and random part, e.g.:
CABBAHCGBABIEAAHBHPSYWUJYKHIYY
This should always be unique (unless you have more than 16 new customers per second, as clock changes 15-16 times per second).
Zoran
karthik parchaPosted Jul 26, 2011, 6:05 AM
thanq thanq very much i will try it if their any doubts i will contact you zoran
yesterday i tried your storedprocedure its working now
hie
can u explain this code plz dont mind
private string GenerateToken(int length)
{
Random rnd = new Random();
StringBuilder sb = new StringBuilder();
string ts = DateTime.UtcNow.ToString("yyyyMMddHHmmssffff");
for (int i = 0; i < ts.Length; i++)
sb.Append((char)(ts[i] - '0' + 'A'));
while (sb.Length < length)
sb.Append((char)(rnd.Next(26) + 'A'));
return sb.ToString();
}
Zoran HorvatPosted Jul 26, 2011, 6:00 AM
Function which generates token can look like this:
private string GenerateToken(int length)
{
Random rnd = new Random();
StringBuilder sb = new StringBuilder();
string ts = DateTime.UtcNow.ToString("yyyyMMddHHmmssffff");
for (int i = 0; i < ts.Length; i++)
sb.Append((char)(ts[i] - '0' + 'A'));
while (sb.Length < length)
sb.Append((char)(rnd.Next(26) + 'A'));
return sb.ToString();
}
private string GenerateToken()
{
return GenerateToken(40);
}
You can use GenerateToken() function and that will generate 40 characters long tokens. First part of the token is created from current timestamp which guarantees uniqueness.
Now suppose that you have a customers table like this:
CREATE TABLE Customer(
CustomerID INT PRIMARY KEY IDENTITY(1, 1),
UserName VARCHAR(100),
MailingListToken CHAR(40)
);
In this case, you can create Subscribe and Unsubscribe stored procedures:
CREATE PROCEDURE Subscribe
@CustomerID INT,
@Token CHAR(40)
AS
BEGIN
UPDATE Customer SET MailingListToken=@Token WHERE CustomerID=@CustomerID
END
GO
CREATE PROCEDURE Unsubscribe
@Token CHAR(40)
AS
BEGIN
UPDATE Customer SET MailingListToken=NULL WHERE MailingListToken=@Token
END
GO
You can extract the list of subscribed customers like this:
SELECT CustomerID, UserName FROM Customer WHERE MailingListToken IS NOT NULL;
Zoran
karthik parchaPosted Jul 26, 2011, 5:44 AM
What you said i understand
But How to write code for this Token should be a relatively long string which is randomly generated and unique
If you know can u write code for me
If you have any example application or just sample overview regarding this task will you post for me