Ejemplo n.º 1
0
        public static void SendWelcomeEmail(model.User user)
        {
            string templatePath = string.Empty;

            if (_folderEmailTemplate.Length == 0)
            {
                templatePath =
                    AppDomain.CurrentDomain.BaseDirectory.Replace(
                        @"backSimulatorForBadDriver\bin\Debug",
                        @"badDriverWebMockup\emailTemplate") + "welcome.html";
            }
            else
            {
                templatePath = string.Format("{0}{1}", _folderEmailTemplate, "welcome.html");
            }

            string templateString = string.Empty;

            List <KeyValuePair <string, string> > toFrom = new List <KeyValuePair <string, string> >();

            toFrom.Add(new KeyValuePair <string, string>("##TitleWelcome", "Bem-vinda ao BadDriver"));
            toFrom.Add(new KeyValuePair <string, string>("##nickname", user.Nickname));
            toFrom.Add(new KeyValuePair <string, string>("##link", "LINK_TBD"));

            List <string> lines = new List <string>();

            lines = File.ReadAllLines(templatePath).ToList();

            foreach (var l in lines)
            {
                templateString += l;
            }

            utils.Email.sendEmail(string.Format("Welcome to BadDriver {0}", user.Nickname), templateString, true, toFrom, user.Email);
        }
Ejemplo n.º 2
0
        public static bool UpdateUser(model.User user)
        {
            bool result = false;

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>("@id", user.Id.ToString()));
            parameters.Add(new KeyValuePair <string, object>("@email", user.Email));
            parameters.Add(new KeyValuePair <string, object>("@Nickname", user.Nickname));
            parameters.Add(new KeyValuePair <string, object>("@password", user.Password));
            parameters.Add(new KeyValuePair <string, object>("@active", user.Active.ToString()));

            try
            {
                utils.DatabaseHelper.ExecuteNonQuery(parameters, "procUser_update", null);
                result = true;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
            }

            return(result);
        }
Ejemplo n.º 3
0
        public static model.User CreateUser(model.User user)
        {
            model.User result = new model.User();

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>("@email", user.Email));
            parameters.Add(new KeyValuePair <string, object>("@nickname", user.Nickname));
            parameters.Add(new KeyValuePair <string, object>("@password", user.Password));


            try
            {
                user.Id = (Int32)utils.DatabaseHelper.ExecuteNonQuery(
                    parameters,
                    "procUser_Create",
                    new KeyValuePair <string, object>("@Id", user.Id));

                user.Active = true;

                result = user;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally { }

            return(result);
        }
Ejemplo n.º 4
0
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            model.User user = new model.User()
            {
                Active = false,

                Id       = 0,
                Nickname = NicknameTextBox.Text,
                Password = PasswordTextBox.Text
            };

            try
            {
                user = service.User.CreateUser(user);
                user = service.User.GetUserByIOrEmailOrUsernameAndPassword(0, user.Email, user.Nickname, user.Password);
                if (user.Id == 0)
                {
                    throw new Exception("User not created.");
                }
                else
                {
                    Response.Redirect(string.Format("~/ConfirmacaoCadastro.aspx?ID={0}", user.Id.ToString()), true);
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        protected void LoginButton_Click(object sender, EventArgs e)
        {
            try
            {
                model.User user =
                    service.User.GetUserByIOrEmailOrUsernameAndPassword(
                        0,
                        UserEmailTextBox.Text,
                        UserEmailTextBox.Text,
                        PasswordTextBox.Text);

                if (user.Id > 0)
                {
                    Session["UserId"]    = user.Id;
                    Session["UserEmail"] = user.Email;
                    FormsAuthentication.RedirectFromLoginPage(user.Nickname, RememberMeSetCheckBox.Checked);
                }

                Response.Write(string.Format("id: {0} , email: {1} , nickname {2}, active {3}", user.Id, user.Email, user.Nickname, user.Active));
            }
            catch (Exception)
            {
                throw;
            }
        }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            model.User user =
                service.User.GetUserById(Convert.ToInt32(Request["ID"].ToString()));

            LabelMensagem.Text =
                string.Format("Usuário <strong>{0}</strong> registrado, confirme seu registro pelo link que será enviado no seu e-mail {1}.", user.Nickname, user.Email);
        }
Ejemplo n.º 7
0
        private static model.User GetUserByEmailOrUsername(string email, string username)
        {
            model.User result = new model.User();

            if (email.Length > 0)
            {
                result = GetUserByEmail(email);
            }
            else if (username.Length > 0)
            {
                result = GetUserByUsername(username);
            }

            return(result);
        }
Ejemplo n.º 8
0
        public static bool ResetUserPasswordByEmailOrUsername(string email, string username)
        {
            bool result = false;

            model.User userToUpdate = GetUserByEmailOrUsername(email, username);

            userToUpdate.Active = false;

            userToUpdate.Password = utils.Security.NewPassword();

            bool userUpdated = UpdateUser(userToUpdate);

            if (userUpdated)
            {
                result = true;
            }

            return(result);
        }
Ejemplo n.º 9
0
        public static model.User GetUserByIOrEmailOrUsernameAndPassword(int id, string email, string username, string password)
        {
            model.User result = new model.User();

            List <KeyValuePair <string, object> > parameters = new List <KeyValuePair <string, object> >();

            parameters.Add(new KeyValuePair <string, object>("@id", id));
            parameters.Add(new KeyValuePair <string, object>("@email", email));
            parameters.Add(new KeyValuePair <string, object>("@nickname", username));
            parameters.Add(new KeyValuePair <string, object>("@password", password));
            IDataReader reader = null;

            try
            {
                using (reader = utils.DatabaseHelper.ExecuteReader(parameters, "procUser_read"))
                {
                    if (reader.Read())
                    {
                        result.Id       = (int)reader["Id"];
                        result.Email    = reader["email"].ToString();
                        result.Nickname = reader["nickname"].ToString();
                        result.Active   = (bool)reader["active"];
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                if (reader.IsClosed == false)
                {
                    reader.Close();
                    reader.Dispose();
                }
            }

            return(result);
        }
Ejemplo n.º 10
0
        private static void testUserFeatures()
        {
            // Create user
            model.User userToBeCreated = new model.User()
            {
                Active   = false,
                Email    = email.Replace("teste", Guid.NewGuid().ToString()),
                Id       = 0,
                Nickname = Guid.NewGuid().ToString(),
                Password = password
            };

            userToBeCreated = service.User.CreateUser(userToBeCreated);
            Console.WriteLine("User {0} created with id {1}", userToBeCreated.Nickname, userToBeCreated.Id);

            // E-mail send welcome
            model.User userToReceiveEmail = new model.User()
            {
                Active   = true,
                Email    = email,
                Id       = 1,
                Nickname = nickname,
                Password = password
            };

            service.User.SendWelcomeEmail(userToReceiveEmail);


            // E-mail send password reset link
            Console.WriteLine(string.Format("User updated = {0}", service.User.ResetUserPasswordByEmailOrUsername(email, nickname)));


            // Create user
            model.User newUser = new model.User()
            {
                Active   = true,
                Email    = email,
                Id       = 0,
                Nickname = nickname,
                Password = password
            };
            newUser = service.User.CreateUser(newUser);


            // Get User
            model.User gettedUserById       = service.User.GetUserById(id);
            model.User gettedUserByEmail    = service.User.GetUserByIOrEmailOrUsernameAndPassword(4, "*****@*****.**", string.Empty, "123456");
            model.User gettedUserByNickname = service.User.GetUserByIOrEmailOrUsernameAndPassword(0, string.Empty, nickname, password);


            // User reset password
            bool resetUserPasswordByEmail    = service.User.ResetUserPasswordByEmailOrUsername(email, string.Empty);
            bool resetUserPasswordByNickname = service.User.ResetUserPasswordByEmailOrUsername(string.Empty, nickname);

            // Update User
            model.User userToUpdate = service.User.GetUserById(1);
            userToUpdate.Nickname = newNickname;

            bool userUpdated = service.User.UpdateUser(userToUpdate);


            List <KeyValuePair <string, string> > values = new List <KeyValuePair <string, string> >();

            values.Add(new KeyValuePair <string, string>("##user", "bacana"));

            //utils.Email.sendEmail(@"C:\Users\oscar.l.casagrande\Source\Repos\baddriver\badDriverCore\badDriverWebMockup\emailTemplate\welcome.html",
            //    "*****@*****.**",
            //    "*****@*****.**",
            //    "teste",
            //    "teste",
            //    true,
            //    values);
        }
Ejemplo n.º 11
0
 public static bool UpdateUser(model.User user)
 {
     return(domain.User.UpdateUser(user));
 }
Ejemplo n.º 12
0
 public static void SendWelcomeEmail(model.User user)
 {
     domain.User.SendWelcomeEmail(user);
 }
Ejemplo n.º 13
0
 public static model.User CreateUser(model.User user)
 {
     return(domain.User.CreateUser(user));
 }