PDA-Bank-Cards-Info

Форк
0
165 строк · 6.2 Кб
1
using System;
2
using System.Web;
3
using System.Web.Security;
4
using System.Configuration;
5
using System.Web.Configuration;
6
using System.IO;
7
using System.Collections.Specialized;
8

9
/// <summary>
10
/// Summary description for Bank
11
/// </summary>
12
public class Bank
13
{
14
    public Bank()
15
    {
16
            //
17
            // TODO: Add constructor logic here
18
            //
19
    }
20
    /*
21
    private static string CurString(decimal value)
22
    {
23
        return "<b>" + value.ToString("F2") + "</b>";
24
    }
25
    public static string CurByCode(decimal value, string code)
26
    {
27
        return CurString(value) + " " + code;
28
    }
29
    public static string CurByCode(object value, object code)
30
    {
31
        return CurString((decimal)value) + " " + (string)code;
32
    }
33
     */
34

35
    public const string sadmin = "admin"; //"********";
36
    public const string admins = "admins";
37
    public const string operators = "operators";
38

39
    public const string dateFormat = "dd.MM.yy";
40

41
    public 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;
49
        return ConfigurationManager.ConnectionStrings["ConnectionDataMart"].ConnectionString;
50
    }
51

52
    public static string AppSetting(string key)
53
    {
54
        Configuration rootWebConfig =
55
            WebConfigurationManager.OpenWebConfiguration("~");
56
        if (rootWebConfig.AppSettings.Settings.Count > 0)
57
        {
58
            KeyValueConfigurationElement customSetting =
59
                rootWebConfig.AppSettings.Settings[key];
60
            if (customSetting != null)
61
                return customSetting.Value;
62
        }
63
        return "";
64
    }
65

66
    public static bool CreateUser(string userName, string userPass, string userEmail,
67
        out string errMessage)
68
    {
69
        //MembershipCreateStatus result;
70
        errMessage = "";
71
        try
72
        {
73
            MembershipUser newUser = Membership.CreateUser(userName, userPass, userEmail);
74
            return true;
75
        }
76
        catch (MembershipCreateUserException e)
77
        {
78
            errMessage = GetErrorMessage(e.StatusCode);
79
            return false;
80
        }
81
        catch (HttpException e)
82
        {
83
            errMessage = e.Message;
84
            return false;
85
        }
86
    }
87
    public static string GetErrorMessage(MembershipCreateStatus status)
88
    {
89
        switch (status)
90
        {
91
            case MembershipCreateStatus.DuplicateUserName:
92
                return "Username already exists. Please enter a different user name.";
93

94
            case MembershipCreateStatus.DuplicateEmail:
95
                return "A username for that e-mail address already exists. Please enter a different e-mail address.";
96

97
            case MembershipCreateStatus.InvalidPassword:
98
                return "The password provided is invalid. Please enter a valid password value.";
99

100
            case MembershipCreateStatus.InvalidEmail:
101
                return "The e-mail address provided is invalid. Please check the value and try again.";
102

103
            case MembershipCreateStatus.InvalidAnswer:
104
                return "The password retrieval answer provided is invalid. Please check the value and try again.";
105

106
            case MembershipCreateStatus.InvalidQuestion:
107
                return "The password retrieval question provided is invalid. Please check the value and try again.";
108

109
            case MembershipCreateStatus.InvalidUserName:
110
                return "The user name provided is invalid. Please check the value and try again.";
111

112
            case MembershipCreateStatus.ProviderError:
113
                return "The authentication provider returned an error. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
114

115
            case MembershipCreateStatus.UserRejected:
116
                return "The user creation request has been canceled. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
117

118
            default:
119
                return "An unknown error occurred. Please verify your entry and try again. If the problem persists, please contact your system administrator.";
120
        }
121
    }
122
    public static StringCollection GetAvailableThemes()
123
    {
124
        string path = HttpContext.Current.Request.PhysicalApplicationPath + @"App_Themes";
125
        DirectoryInfo dir = new DirectoryInfo(path);
126
        StringCollection themes = new StringCollection();
127
        foreach (DirectoryInfo di in dir.GetDirectories())
128
            themes.Add(di.Name);
129
        return themes;
130
    }
131
    public static string GetNextTheme(string theme)
132
    {
133
        StringCollection themes = GetAvailableThemes();
134
        int i = themes.IndexOf(theme) + 1;
135
        if (i == themes.Count)
136
            i = 0;
137
        return themes[i];
138
    }
139
    public static void Log(string file, string text, params Object[] args)
140
    {
141
        string path = HttpContext.Current.Request.PhysicalApplicationPath + @"App_Data\\" + file;
142
        File.AppendAllText(path, String.Format(text, args));
143
    }
144
    public static void LoginLog(string user)
145
    {
146
        //Bank.Log("{0} {1} {2} \"{3}\"\n", DateTime.Now, user, Request.UserHostAddress, Request.UserAgent);
147
        HttpContext ctx = HttpContext.Current;
148
        string file = String.Format("login.{0:yyyy'.'MM}.log", DateTime.Now);
149
        Log(file, "{0} {1} {2} \"{3}\"\n", DateTime.Now,
150
            user, //ctx.Request.User.Identity.Name,
151
            ctx.Request.UserHostAddress,
152
            ctx.Request.UserAgent);
153
    }
154
    public static void HackLog(string user, string pass)
155
    {
156
        //Bank.Log("{0} {1} {2} \"{3}\"\n", DateTime.Now, user, Request.UserHostAddress, Request.UserAgent);
157
        HttpContext ctx = HttpContext.Current;
158
        string file = String.Format("hack.{0:yyyy'.'MM}.log", DateTime.Now);
159
        Log(file, "{0} {1}/{2} {3} \"{4}\"\n", DateTime.Now,
160
            user, //ctx.Request.User.Identity.Name,
161
            pass,
162
            ctx.Request.UserHostAddress,
163
            ctx.Request.UserAgent);
164
    }
165
}
166

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.