public Stream CreateUser(string nuid, string pin) { int status = 0; try { QuickFactorAuthenticationServiceModel tstDb = new QuickFactorAuthenticationServiceModel(); authentication_info authInfo = new authentication_info(); authInfo.NUID = nuid; authInfo.PIN = pin; tstDb.authentication_info.Add(authInfo); status = tstDb.SaveChanges(); } catch (DbUpdateException ex) { var sqlex = ex.InnerException.InnerException as SqlException; if (sqlex != null) { switch (sqlex.Number) { case 2627: status = 2; break; default: status = -1; break; } } } catch (Exception ex) { status = -1; } StringBuilder sb = new StringBuilder(); sb.AppendLine("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); sb.AppendLine("<html xmlns=\"http://www.w3.org/1999/xhtml\">"); sb.AppendLine("<head>"); sb.AppendLine("<title>Create User</title>"); sb.AppendLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=ISO-8859-1\">"); sb.AppendLine("</head>"); sb.AppendLine("<body>"); sb.AppendLine("<center>"); sb.AppendFormat("<h1>User Created {0}</h1>", status); sb.AppendLine("</center>"); sb.AppendLine("</body>"); sb.AppendLine("</html>"); byte[] resultBytes = Encoding.UTF8.GetBytes(sb.ToString()); WebOperationContext.Current.OutgoingResponse.ContentType = "text/html"; WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK; return(new MemoryStream(resultBytes)); }
public System.IO.Stream SetSecretDate(string nuid, string secretDate, string sessionId) { string status = "0"; string result = "0"; try { IList <authentication_info> authInfo = GetAuthInfoByNuid(nuid); if (authInfo == null || authInfo.Count() == 0) { status = "1"; } else if (authInfo.Count() > 1) { status = "2"; } else { if (authInfo.First().PIN.Equals("DISABLED")) { status = "-1"; result = "User Already Registered"; } } string encryptSecretDate = ClsTripleDES.Encrypt(secretDate); try { QuickFactorAuthenticationServiceModel tstDb = new QuickFactorAuthenticationServiceModel(); authInfo.First().PIN = "DISABLED"; authInfo.First().ANSWER = encryptSecretDate; tstDb.authentication_info.AddOrUpdate(authInfo.First()); int saveStatus = tstDb.SaveChanges(); } catch (Exception ex) { status = "-1"; result = ex.Message; } } catch (Exception ex) { status = "-1"; result = ex.Message; } StringBuilder sb = new StringBuilder(); sb.AppendLine("<!DOCTYPE html PUBLIC \" -//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">"); sb.AppendLine("<html xmlns = \"http://www.w3.org/1999/xhtml\">"); sb.AppendLine("<head>"); sb.AppendLine("<title> Password Express - IVR SetSecretDate </title>"); sb.AppendLine("<meta http - equiv = \"Content -Type\" content = \"text/html; charset=ISO-8859-1\">"); sb.AppendLine("</head>"); sb.AppendLine("<body>"); sb.AppendLine("<center>"); sb.AppendLine("<h1> IVR Secret Date Page </h1>"); sb.AppendFormat("<h2> Status: {0}</h2>", status); sb.AppendFormat("<h3> Result: {0}</h3>", result); sb.AppendFormat("<status> {0} </status>", status); sb.AppendFormat("<result>{0}</result>", result); sb.AppendFormat("<sessionID> {0} </sessionID>", sessionId); sb.AppendLine("</center>"); sb.AppendLine("</body>"); sb.AppendLine("</html>"); byte[] resultBytes = Encoding.UTF8.GetBytes(sb.ToString()); WebOperationContext.Current.OutgoingResponse.ContentType = "text/html"; WebOperationContext.Current.OutgoingResponse.StatusCode = System.Net.HttpStatusCode.OK; return(new MemoryStream(resultBytes)); }