예제 #1
0
        public void DALTest1()
        {
            using (StepMapDbContext ctx = new StepMapDbContext())
            {
                User u = new User();
                u.Email = "*****@*****.**";
                u.LastLogin = DateTime.UtcNow;
                u.Name = "test user";
                u.PasswordHash = "hash";
                u.UserRole = UserRole.Member;
                u.UserState = UserState.Active;

                u = ctx.Users.Add(u);
                ctx.SaveChanges();
                try
                {
                    User du = ctx.Users.Single(tu => tu.Email == "*****@*****.**");
                    Assert.AreEqual(u.LastLogin, du.LastLogin);
                    Assert.AreEqual(u.Name, du.Name);
                    Assert.AreEqual(u.PasswordHash, du.PasswordHash);
                    Assert.AreEqual(u.UserRole, du.UserRole);
                    Assert.AreEqual(u.UserState, du.UserState);
                }
                finally
                {
                    ctx.Users.Remove(u);
                    ctx.SaveChanges();
                }
            }
        }
예제 #2
0
 public static dal.User ConvertUser(dto.User user)
 {
     dal.User ret = new dal.User();
     ret.Id = user.Id;
     ret.Name = user.Name;
     ret.Email = user.Email;
     return ret;
 }
예제 #3
0
        public void DALTest2()
        {
            using (StepMapDbContext ctx = new StepMapDbContext())
            {
                User u = new User();
                u.Email = "*****@*****.**";
                u.LastLogin = DateTime.UtcNow;
                u.Name = "test user";
                u.PasswordHash = "hash";
                u.UserRole = UserRole.Member;
                u.UserState = UserState.Active;

                Project p = new Project();
                p.Name = "test project";
                p.User = u;

                Step s = new Step();
                s.Name = "test step name";
                s.Project = p;

                Reminder r = new Reminder();
                r.Step = s;
                r.EmailAddress = "*****@*****.**";
                r.Message = "test message";
                r.SentDate = DateTime.UtcNow;
                r.Subject = "test subject";

                ctx.Projects.Add(p);
                ctx.Steps.Add(s);
                ctx.Reminders.Add(r);

                ctx.SaveChanges();

                try
                {
                    Project dp = ctx.Projects.Single(tu => tu.Name == "test project");
                    Assert.AreEqual(p.UserId, dp.UserId);
                    Step ds = dp.FinishedSteps.Single();
                    Assert.AreEqual(s.Name, ds.Name);
                    Reminder dr = ds.SentReminders.Single();
                    Assert.AreEqual(dr.EmailAddress, r.EmailAddress);
                    Assert.AreEqual(dr.Message, r.Message);
                    Assert.AreEqual(dr.SentDate, r.SentDate);
                    Assert.AreEqual(dr.Subject, r.Subject);
                }
                finally
                {
                    s.SentReminders.Clear();
                    p.FinishedSteps.Clear();
                    ctx.Reminders.Remove(r);
                    ctx.Steps.Remove(s);
                    ctx.Projects.Remove(p);
                    ctx.Users.Remove(u);
                    ctx.SaveChanges();
                }
            }
        }
        //[Ignore]
        public void TestMethod1()
        {
            var logger = new Mock<ILogger>();
            var config = new Mock<IStepMapConfig>();
            config.Setup(x => x.NotificationAccount).Returns("*****@*****.**");
            config.Setup(x => x.GmailClientId).Returns("");
            config.Setup(x => x.GmailApiClientSecret).Returns("");

            NotificationManager nm = new NotificationManager(logger.Object, config.Object);
            User user = new User{ Email = "*****@*****.**", Name = "kemy" };
            nm.SendEmail(user, "Unit test", "Test text");
        }
예제 #5
0
 public IEnumerable<Project> GetProjects(User user)
 {
     List<Project> ret = new List<Project>(7);
     using (var ctx = new StepMapDbContext())
     {
         var pl = ctx.Projects.Where(p => p.UserId == user.Id).Include(s => s.FinishedSteps).Include(s => s.User).ToList();
         for (int i = 0; i < 7; i++)
         {
            ret.Add(pl.SingleOrDefault(p => p.Position == i));
         }
     }
     return ret;
 }
예제 #6
0
        public void SendEmail(User user, string subject, string text)
        {
            var msg = new AE.Net.Mail.MailMessage
            {
                Subject = subject,
                Body = text,
                From = new MailAddress(config.NotificationAccount)
            };
            msg.To.Add(new MailAddress(user.Email));
            msg.ReplyTo.Add(msg.From); // Bounces without this!!
            var msgStr = new StringWriter();
            msg.Save(msgStr);

            var m = new Message { Raw = Base64UrlEncode(msgStr.ToString()) };
            gmailService.Value.Users.Messages.Send(m, "me").Execute();
        }
예제 #7
0
        private void SendConfirmationEmail(User user)
        {
            using (var ctx = new StepMapDbContext())
            {
                user = ctx.Users.Attach(user);
                UserConfirmation uc = new UserConfirmation();
                uc.User = user;
                uc.ConfirmationGuid = Guid.NewGuid().ToString();

                ctx.UserConfirmations.Add(uc);
                ctx.SaveChanges();
                
                string link = config.ClientBaseAddress + "/Account/ConfirmEmail/?guid=" + uc.ConfirmationGuid;
                //TODO: do not hardcode text
                notificationManager.SendEmail(user, "registration on stepmap.xyz", string.Format("you are registered on stepmap.xyz. please confirm your accout visiting this link: {0}!", link)); //LOCSTR
            }
        }
예제 #8
0
 private void SentFirstReminder(User user, Project project, Step step)
 {
     using (var ctx = new StepMapDbContext())
     {
         //TODO: Config, customize, randomize
         Reminder reminder = new Reminder()
         {
             EmailAddress = user.Email,
             Message = string.Format("Your current step ({0}) in project {1} is delayed! Get yourself together!", step.Name, project.Name), //LOCSTR
             Subject = "First reminder", //LOCSTR
             SentDate = DateTime.UtcNow,
             StepId = step.Id
         };
         ctx.Reminders.Add(reminder);
         notificationManager.SendEmail(user, reminder.Subject, reminder.Message);
         ctx.SaveChanges();
     }
 }
예제 #9
0
        public void Register(string userName, string email, string pwdHash)
        {
            bool isValid = regexHelper.IsValidEmail(email);
            if (isValid)
            {
                using (var ctx = new StepMapDbContext())
                {
                    User oldUser = ctx.Users.SingleOrDefault(u => u.Name == userName);
                    if (oldUser == null)
                    {
                        User oldEmail = ctx.Users.SingleOrDefault(u => u.Email == email);

                        if (oldEmail == null)
                        {
                            User user = new User() { Name = userName, Email = email, PasswordHash = pwdHash, UserRole = UserRole.Member, UserState = UserState.NotActivatedYet };
                            user = ctx.Users.Add(user);
                            ctx.SaveChanges();

                            SendConfirmationEmail(user);
                        }
                        else
                        {
                            throw new UserAlreadyExistException(string.Format("Email already exist! {0}", email));
                        }
                    }
                    else
                    {
                        throw new UserAlreadyExistException(string.Format("User name already exist! {0}", userName));
                    }
                }
            }
            else
            {
                logger.Warning("Attempt to register invalid email: {0}! Username: {1}.", email, userName);
            }
        }
예제 #10
0
        public void DALTest3()
        {
            using (StepMapDbContext ctx = new StepMapDbContext())
            {
                User u = new User();
                u.Email = "*****@*****.**";
                u.LastLogin = DateTime.UtcNow;
                u.Name = "test user";
                u.PasswordHash = "hash";
                u.UserRole = UserRole.Member;
                u.UserState = UserState.Active;

                u = ctx.Users.Add(u);
                ctx.SaveChanges();

                UserConfirmation uc = new UserConfirmation();
                uc.User = u;
                uc.ConfirmationGuid = "guid";
                uc = ctx.UserConfirmations.Add(uc);
                ctx.SaveChanges();

                try
                {
                    UserConfirmation du = ctx.UserConfirmations.Single(tu => tu.ConfirmationGuid == "guid");
                    Assert.AreEqual(u.Id, du.User.Id);
                }
                finally
                {
                    ctx.UserConfirmations.Remove(uc);
                    ctx.Users.Remove(u);
                    ctx.SaveChanges();
                }
            }
        }
예제 #11
0
        public void Login(User user)
        {
            using (var ctx = new StepMapDbContext())
            {
                user = ctx.Users.Attach(user);

                if (user.UserState == UserState.Active)
                {
                    user.LastLogin = DateTime.UtcNow;
                    ctx.SaveChanges();
                }
                else
                {
                    throw new AccountIsNotActivatedException("Please confirm your email: " + user.Email);
                }
            }
        }