Exemplo n.º 1
0
        protected void Button2_Click(object sender, EventArgs e)
        {
            /*
             * FCUser tmp = new FCUser
             * {
             *      id = -1,
             *      name = UserName.Text,
             *      pass = Password.Text,
             *      g = Guid.Empty,
             *      status = FCUser.eStatus.eDisabled
             * };
             */
            // verify the user
            FCUser user = Repository.LoginUser(UserName.Text, Password.Text);

            if (user == null ||
                user.status != FCUser.eStatus.eEnabled)
            {
                // can't login
                return;
            }

            Session["user"] = user;

            if (CheckBox1.Enabled)
            {
                FormsAuthentication.SetAuthCookie(UserName.Text, true);
            }

            Repository.sIsLogedIn = true;
        }
Exemplo n.º 2
0
        public static FCUser CreateUser(string n, string p)
        {
            FCUser newUser = new FCUser {
                name = n, pass = p, status = FCUser.eStatus.eDisabled, g = Guid.NewGuid()
            };

            // creates or confirms user
#if _LINQXML_
            DataHelperLinqXml.AddEntryPointHistory(epl);
#elif _SQLITE_
            using (var ctx = new ConnectionContextSQLite())
            {
                if (!DataHelperSQLite.CreateUser(ctx, newUser))
                {
                    return(null);
                }

                return(newUser);
            }
#else // _MYSQL_
            using (var ctx = new ConnectionContextMySQL())
            {
                return(DataHelper.CreateUser(ctx, user));
            }
#endif
        }
Exemplo n.º 3
0
        public bool CreateUser(string name, string pass)
        {
            FCUser newUser = Repository.CreateUser(name, pass);

            if (newUser == null)
            {
                return(false);
            }

            string newUserGuidStr = newUser.g.ToString("B");                    // 38 chars, e.g. {12345678-1234-1234-1234-123456789abc}

            // send confirmation email
            string domainName       = Request.Url.GetLeftPart(UriPartial.Authority) + Request.ApplicationPath;
            string confirmationPage = "Pages/EmailConfirmation.aspx?ID=" + newUserGuidStr;
            string url = domainName + confirmationPage;

            MailAddress to   = new MailAddress(newUser.name);
            MailAddress from = new MailAddress("*****@*****.**");

            var message = new MailMessage(from, to);

            try
            {
                string path = AppDomain.CurrentDomain.GetData("DataDirectory").ToString() + "\\user_data\\";

                using (StreamReader sr = new StreamReader(path + "NewUserMail.txt"))
                {
                    message.Body = sr.ReadToEnd();
                }
            }
            catch (Exception e)
            {
                Utilities.Logger.WriteError(String.Format("CreateUser() failed - {0}", e.Message));
                //Console.WriteLine("The file could not be read:");
                //Console.WriteLine(e.Message);

                return(false);
            }

            message.Subject = "[fincurve.com] Registration confirmation";
            message.Body    = message.Body.Replace("<%UserName%>", newUser.name);
            message.Body    = message.Body.Replace("<%VerificationUrl%>", url);

            SmtpClient smtp = new SmtpClient();

            smtp.Host = "smtp.gmail.com";
            smtp.Port = 587;

            NameValueCollection tmp = ConfigurationManager.AppSettings;
            string adminEmailName   = tmp["AdminEmailName"];
            string adminEmailPass   = tmp["AdminEmailPass"];

            smtp.UseDefaultCredentials = false;
            smtp.Credentials           = new System.Net.NetworkCredential(adminEmailName, adminEmailPass);
            smtp.EnableSsl             = true;

            smtp.Send(message);
            //e.Cancel = true;

            return(true);
        }