PDA-Bank-Cards-Info
165 строк · 6.2 Кб
1using System;
2using System.Web;
3using System.Web.Security;
4using System.Configuration;
5using System.Web.Configuration;
6using System.IO;
7using System.Collections.Specialized;
8
9/// <summary>
10/// Summary description for Bank
11/// </summary>
12public class Bank
13{
14public Bank()
15{
16//
17// TODO: Add constructor logic here
18//
19}
20/*
21private static string CurString(decimal value)
22{
23return "<b>" + value.ToString("F2") + "</b>";
24}
25public static string CurByCode(decimal value, string code)
26{
27return CurString(value) + " " + code;
28}
29public static string CurByCode(object value, object code)
30{
31return CurString((decimal)value) + " " + (string)code;
32}
33*/
34
35public const string sadmin = "admin"; //"********";
36public const string admins = "admins";
37public const string operators = "operators";
38
39public const string dateFormat = "dd.MM.yy";
40
41public static string ConnectionString()
42{
43//Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
44//SectionInformation asInfo = config.AppSettings.SectionInformation;
45//SectionInformation csInfo = config.ConnectionStrings.SectionInformation;
46
47//txt = ConfigurationManager.AppSettings["key"];
48//txt = ConfigurationManager.ConnectionStrings["key"].ConnectionString;
49return ConfigurationManager.ConnectionStrings["ConnectionDataMart"].ConnectionString;
50}
51
52public static string AppSetting(string key)
53{
54Configuration rootWebConfig =
55WebConfigurationManager.OpenWebConfiguration("~");
56if (rootWebConfig.AppSettings.Settings.Count > 0)
57{
58KeyValueConfigurationElement customSetting =
59rootWebConfig.AppSettings.Settings[key];
60if (customSetting != null)
61return customSetting.Value;
62}
63return "";
64}
65
66public static bool CreateUser(string userName, string userPass, string userEmail,
67out string errMessage)
68{
69//MembershipCreateStatus result;
70errMessage = "";
71try
72{
73MembershipUser newUser = Membership.CreateUser(userName, userPass, userEmail);
74return true;
75}
76catch (MembershipCreateUserException e)
77{
78errMessage = GetErrorMessage(e.StatusCode);
79return false;
80}
81catch (HttpException e)
82{
83errMessage = e.Message;
84return false;
85}
86}
87public static string GetErrorMessage(MembershipCreateStatus status)
88{
89switch (status)
90{
91case MembershipCreateStatus.DuplicateUserName:
92return "Username already exists. Please enter a different user name.";
93
94case MembershipCreateStatus.DuplicateEmail:
95return "A username for that e-mail address already exists. Please enter a different e-mail address.";
96
97case MembershipCreateStatus.InvalidPassword:
98return "The password provided is invalid. Please enter a valid password value.";
99
100case MembershipCreateStatus.InvalidEmail:
101return "The e-mail address provided is invalid. Please check the value and try again.";
102
103case MembershipCreateStatus.InvalidAnswer:
104return "The password retrieval answer provided is invalid. Please check the value and try again.";
105
106case MembershipCreateStatus.InvalidQuestion:
107return "The password retrieval question provided is invalid. Please check the value and try again.";
108
109case MembershipCreateStatus.InvalidUserName:
110return "The user name provided is invalid. Please check the value and try again.";
111
112case MembershipCreateStatus.ProviderError:
113return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
114
115case MembershipCreateStatus.UserRejected:
116return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
117
118default:
119return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
120}
121}
122public static StringCollection GetAvailableThemes()
123{
124string path = HttpContext.Current.Request.PhysicalApplicationPath + @"App_Themes";
125DirectoryInfo dir = new DirectoryInfo(path);
126StringCollection themes = new StringCollection();
127foreach (DirectoryInfo di in dir.GetDirectories())
128themes.Add(di.Name);
129return themes;
130}
131public static string GetNextTheme(string theme)
132{
133StringCollection themes = GetAvailableThemes();
134int i = themes.IndexOf(theme) + 1;
135if (i == themes.Count)
136i = 0;
137return themes[i];
138}
139public static void Log(string file, string text, params Object[] args)
140{
141string path = HttpContext.Current.Request.PhysicalApplicationPath + @"App_Data\\" + file;
142File.AppendAllText(path, String.Format(text, args));
143}
144public static void LoginLog(string user)
145{
146//Bank.Log("{0} {1} {2} \"{3}\"\n", DateTime.Now, user, Request.UserHostAddress, Request.UserAgent);
147HttpContext ctx = HttpContext.Current;
148string file = String.Format("login.{0:yyyy'.'MM}.log", DateTime.Now);
149Log(file, "{0} {1} {2} \"{3}\"\n", DateTime.Now,
150user, //ctx.Request.User.Identity.Name,
151ctx.Request.UserHostAddress,
152ctx.Request.UserAgent);
153}
154public static void HackLog(string user, string pass)
155{
156//Bank.Log("{0} {1} {2} \"{3}\"\n", DateTime.Now, user, Request.UserHostAddress, Request.UserAgent);
157HttpContext ctx = HttpContext.Current;
158string file = String.Format("hack.{0:yyyy'.'MM}.log", DateTime.Now);
159Log(file, "{0} {1}/{2} {3} \"{4}\"\n", DateTime.Now,
160user, //ctx.Request.User.Identity.Name,
161pass,
162ctx.Request.UserHostAddress,
163ctx.Request.UserAgent);
164}
165}
166