Пример #1
0
 public RazorEmailResult SendAccountDelete(User model)
 {
     To.Add(model.Email);
     From = "*****@*****.**";
     Subject = "Delete Account";
     return Email("SendAccountDelete", model);
 }
Пример #2
0
 public RazorEmailResult SendAccountVerified(User model)
 {
     To.Add(model.Email);
     From = "*****@*****.**";
     Subject = "Account Verification";
     return Email("SendAccountVerified", model);
 }
Пример #3
0
 public RazorEmailResult SendAccountNameReminder(User model)
 {
     To.Add(model.Email);
     From = "*****@*****.**";
     Subject = "Here's your missing Username";
     return Email("SendAccountNameReminder", model);
 }
Пример #4
0
 public RazorEmailResult SendChangeEmailRequestNotice(User model)
 {
     To.Add(model.Email);
     From = "*****@*****.**";
     Subject = "Email Request Notice";
     return Email("SendChangeEmailRequestNotice", model);
 }
Пример #5
0
 public RazorEmailResult SendEmailChangedNotice(User model)
 {
     To.Add(model.Email);
     From = "*****@*****.**";
     Subject = "Email Changed Notification";
     return Email("SendEmailChangedNotice", model);
 }
        public ActionResult Create(User user)
        {
            _context.Users.Add(user);
            _context.SaveChanges();

            return RedirectToAction("Index");
        }
Пример #7
0
 private static string BuildUrl(User user, string action, string controller, object routeValues = null)
 {
     if (UrlHelper.RequestContext.HttpContext.Request.Url != null)
     {
         string scheme = UrlHelper.RequestContext.HttpContext.Request.Url.Scheme;
         return UrlHelper.Action(action, controller, routeValues, scheme);
     }
     return null;
 }
Пример #8
0
 public static void Delete(User user)
 {
     using (ES1AutomationEntities context = new ES1AutomationEntities())
     {
         context.Users.Attach(user);
         context.Users.Remove(user);
         context.SaveChanges();
     }
 }
        public void sendNotificationForUser(User userToNotify)
        {
            string message = "Dear ";
            message += userToNotify.Username;
            message += " this is a Notification!";

            if(userToNotify.IsPremium)
            {
                message += " -> Additional Information for Premium Users!";
            }

            sendMail.sendMail(userToNotify.EMailAddress, "Notification", message);
        }
Пример #10
0
 public static User Add(User user)
 {
     try {
         using (ES1AutomationEntities context = new ES1AutomationEntities())
         {
             User u = context.Users.Add(user);
             context.SaveChanges();
             return u;
         }
     }
     catch (Exception e)
     {
         ATFEnvironment.Log.logger.Error(e);
         return null;
     }
 }
        public void isPremiumUserMailSendAndValid()
        {
            var user = new User("Premium", "*****@*****.**", true);
            var expectedSubject = "Notification";
            var expectedMessage = "Dear Premium this is a Notification! -> Additional Information for Premium Users!";

            var sendMail = Mock.Create<SendMail>();

            new NotificationService(sendMail).sendNotificationForUser(user);

            Mock.Assert(
                    () => sendMail.sendMail(user.EMailAddress, expectedSubject, expectedMessage),
                    Occurs.Once(),
                    "sendMail() wasn't called as expected!"
                );
        }
        public void isNonPremiumUserMailSentAndValid()
        {
            var user            = new User("A", "*****@*****.**", false);
            var expectedSubject = "Notification";
            var expectedMessage = "Dear A this is a Notification!";

            var sendMail = Mock.Create<SendMail>();

            new NotificationService(sendMail).sendNotificationForUser(user);

            Mock.Assert(
                    () => sendMail.sendMail(user.EMailAddress, expectedSubject, expectedMessage),
                    Occurs.Once(),
                    "sendMail() wasn't called as expected!"
                );
        }
        public virtual void SignIn(User user, bool isPersistant = false)
        {
            Tracing.Information(String.Format("[ClaimsBasedAuthenticationService.Signin] called: {0}", user.Username));

            if (String.IsNullOrWhiteSpace(user.Username)) throw new ArgumentException("username");

            // gather claims
            var claims = new List<Claim>();
            foreach (UserClaim uc in user.Claims)
                claims.Add(new Claim(uc.Type, uc.Value));

            if (!String.IsNullOrWhiteSpace(user.Email))
            {
                claims.Insert(0, new Claim(ClaimTypes.Email, user.Email));
            }
            claims.Insert(0, new Claim(ClaimTypes.AuthenticationMethod, AuthenticationMethods.Password));
            claims.Insert(0, new Claim(ClaimTypes.AuthenticationInstant, DateTime.UtcNow.ToString("s")));
            claims.Insert(0, new Claim(ClaimTypes.Name, user.Username));
            claims.Insert(0, new Claim(ClaimTypes.NameIdentifier, user.Username));

            // create principal/identity
            var id = new ClaimsIdentity(claims, "Forms");
            var cp = new ClaimsPrincipal(id);

            // claims transform
            cp =
                FederatedAuthentication.FederationConfiguration.IdentityConfiguration.ClaimsAuthenticationManager
                    .Authenticate(String.Empty, cp);

            // issue cookie
            var sam = FederatedAuthentication.SessionAuthenticationModule;
            if (sam == null)
                throw new Exception("SessionAuthenticationModule is not configured and it needs to be.");

            var token = new SessionSecurityToken(cp,
                isPersistant
                    ? FormsAuthentication.Timeout
                    : TimeSpan.FromMinutes(SessionHelpers.GetSessionTimeoutInMinutes))
            {
                IsPersistent = isPersistant
            };
            sam.WriteSessionTokenToCookie(token);

            Tracing.Verbose(String.Format("[ClaimsBasedAuthenticationService.Signin] cookie issued: {0}",
                claims.GetValue(ClaimTypes.NameIdentifier)));
        }
        public ActionResult Register(RegisterModel model)
        {
            if (ModelState.IsValid)
            {
                var user = new User();

                user.InjectFrom<UnflatLoopValueInjection>(model);
                user.ShowWelcomePage = true;

                CreateUserStatus createStatus = _userService.CreateUser(user);

                if (createStatus == CreateUserStatus.Success)
                {
                    _messageBus.Publish(new UserCreated(user, Url.AbsoluteAction("Login", "Account")));

                    if (_membershipSetings.RequireAccountVerification)
                    {
                        new Mailer().VerifyAccount(new VerifyAccountModel());

                        // I don't like this
                        // should be return RedirectToAction
                        return View("Success", model);
                    }
                    if (_membershipSetings.AllowLoginAfterAccountCreation)
                    {
                        _authenticationService.SignIn(user, true);
                        TempData.AddSuccessMessage("Welcome to your new account, " + user.Username + "!");
                        return RedirectToAction("Index", "Home");
                    }
                    return View("Confirm", true);
                }

                ModelState.AddModelError(string.Empty, createStatus.GetDescription());
            }

            return View(model);
        }
Пример #15
0
 public RazorEmailResult SendPasswordChangeNotice(User model)
 {
     To.Add(model.Email);
     From = "*****@*****.**";
     Subject = "Your Password has been updated";
     return Email("SendPasswordChangeNotice", model);
 }
 public void SendAccountDelete(User user)
 {
     _controller.SendAccountDelete(user).Deliver();
 }
 public void SendAccountNameReminder(User user)
 {
     _controller.SendAccountNameReminder(user).Deliver();
 }
 public void SendAccountVerified(User user)
 {
     _controller.SendAccountVerified(user).Deliver();
 }
 public void SendChangeEmailRequestNotice(User user, string newEmail)
 {
     _controller.SendChangeEmailRequestNotice(user).Deliver();
 }
 public void SendEmailChangedNotice(User user, string oldEmail)
 {
     _controller.SendEmailChangedNotice(user).Deliver();
 }
 public void SendPasswordChangeNotice(User user)
 {
     _controller.SendPasswordChangeNotice(user).Deliver();
 }
 public void SendResetPassword(User user)
 {
     _controller.SendPasswordReset(user).Deliver();
 }
Пример #23
0
        /// <summary>
        /// Invoked when <see cref="ToEntity"/> operation is about to return.
        /// </summary>
        /// <param name="entity"><see cref="User"/> converted from <see cref="UserDTO"/>.</param>
partial         static void OnEntity(this UserDTO dto, User entity);
Пример #24
0
 public RazorEmailResult SendPasswordReset(User model)
 {
     To.Add(model.Email);
     From = "*****@*****.**";
     Subject = "Password Reset";
     return Email("SendPasswordReset", model);
 }
Пример #25
0
        /// <summary>
        /// Get User by Username and Password
        /// </summary>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static User GetUser(string username, string password)
        {
            string defaultAuthenticationDomain = ATFConfiguration.GetStringValue("DefaultAuthenticationDomain");

            IList<string> pair = username.Split(new[] { @"\" }, StringSplitOptions.RemoveEmptyEntries);

            string domain = string.Empty;

            if (pair.Count == 1)
            {
                username = pair[0];
            }
            else if (pair.Count == 2)
            {
                if (pair[0].ToLower() == "corp" || pair[0].ToLower() == defaultAuthenticationDomain.ToLower())
                {
                    domain = defaultAuthenticationDomain;
                }
                else
                {
                    //we could not support the authentication against other LDAP server.
                    return null;
                }
                username = pair[1];
            }
            else
            {
                return null;
            }

            User user = null;

            using (ES1AutomationEntities context = new ES1AutomationEntities())
            {
                user = context.Users.Where(u => u.Username == username && u.IsActive).SingleOrDefault();
            }

            // add user to db if user not find
            if (user == null)
            {
                domain = defaultAuthenticationDomain;
                if (ADUser.Authenticate(username, password, domain))
                {
                    //add user to db
                    user = new User();
                    user.Description = string.Format("{0} from {1}", username, domain);
                    user.Username = username;
                    user.UserRole = UserRole.Viewer;
                    user.UserType = UserType.AD;
                    user.IsActive = true;
                    user.Email = ADUser.GetEmailAddress(username, password, domain);
                    User.Add(user);
                    return user;
                }
                else
                {
                    //no this user in db, failed to authenticate against the default domain
                    return null;
                }
            }
            else
            {
                // do validation
                switch (user.UserType)
                {
                    case UserType.ATF:

                        if (user.PlainText != password)
                        {
                            return null;
                        }

                        break;

                    case UserType.AD:

                        if (string.IsNullOrWhiteSpace(domain))
                        {
                            domain = defaultAuthenticationDomain;
                        }

                        if (!ADUser.Authenticate(username, password, domain))
                        {
                            return null;
                        }

                        break;

                    default:

                        return null;
                }
            }
            return user;
        }
Пример #26
0
        public ActionResult Create(User user)
        {
            _repository.SaveOrUpdate(user);

            return RedirectToAction("Index");
        }
Пример #27
0
        /// <summary>
        /// Converts this instance of <see cref="UserDTO"/> to an instance of <see cref="User"/>.
        /// </summary>
        /// <param name="dto"><see cref="UserDTO"/> to convert.</param>
        public static User ToEntity(this UserDTO dto)
        {
            if (dto == null) return null;

            var entity = new User();

            entity.UserId = dto.UserId;
            entity.Type = dto.Type;
            entity.Username = dto.Username;
            entity.Password = dto.Password;
            entity.Role = dto.Role;
            entity.IsActive = dto.IsActive;
            entity.Description = dto.Description;
            entity.Email = dto.Email;

            dto.OnEntity(entity);

            return entity;
        }