Beispiel #1
0
        public bool SendAuthenticationEmail(UserDto user, AuthModel authModel, string loginUrl)
        {
            var access = user.AccessList.First(x => x.Id.Equals(authModel.AccessId));

            try
            {
                var body = "Hi!\n" +
                           "\n" +
                           "Browse to the URL below to manage your MCNotifier account.\n" +
                           "\n" +
                           $"{loginUrl}\n" +
                           "\n" +
                           $"This access link will expire on {access.ValidUntil} (UTC).\n" +
                           "\n" +
                           "Regards,\n" +
                           "The MCNotifier Team.";
                const string subject = "Access to your MCNotifier account";
                var message = BuildMessage(user.Email, subject, body);
                SendEmail(message);
            }
            catch (Exception)
            {
                return false;
                // log me
            }

            return true;
        }
Beispiel #2
0
        public bool SendNotificationEmail(UserDto user, MojangProfileModel model, NotificationDto notification)
        {
            var username = model.Name;

            try
            {
                string availableBody;
                string subject;

                switch (notification.Type)
                {
                    case NotificationType.AvailableSoon:
                        availableBody = $"Username '{username}' will be available in {model.AvailableIn}.\n" +
                                        $"We will notify you again if username will be released on {model.AvailableSince.Value.Subtract(TimeSpan.FromDays(7))} (UTC).";
                        subject = $"{username} will be available soon!";
                        break;
                    case NotificationType.ReleasedSoon:
                        availableBody = $"Username '{username}' will be released in {model.AvailableIn}.\n" +
                                        $"We will notify you again on {model.AvailableSince} (UTC).";
                        subject = $"{username} will be released soon!";
                        break;
                    case NotificationType.Available:
                        availableBody =
                            $"Username '{username}' is now available! Change now on https://account.mojang.com/";
                        subject = $"{username} is now available!";
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }

                var body = "Hi!\n" +
                           "\n" +
                           "MCNotifier is happy to notify you about some changes in your watchlist.\n" +
                           $"{availableBody}\n" +
                           "\n" +
                           "Regards,\n" +
                           "The MCNotifier Team.";

                var message = BuildMessage(user.Email, subject, body);
                SendEmail(message);
                notification.LastStatus = true;
            }
            catch (Exception e)
            {
                //log me
                notification.Retries--;
                return false;
            }
            finally
            {
                notification.Modified = DateTime.UtcNow;
            }

            return true;
        }
Beispiel #3
0
 public static UserDto FillUserFromModel(UserModel model, UserDto user)
 {
     return model.FillUserFromModel(user);
 }
Beispiel #4
0
 public bool SetUser(UserDto user)
 {
     lock (Lock)
     {
         var query = new UserQuery(user.Email);
         return _userQueryHandler.SetById<UserDto>(query, user);
     }
 }
Beispiel #5
0
        public bool Login(UserModel model)
        {
            var authModel = new AuthModel(model.Email);
            var user = GetUser(model.Email);

            if (user == null)
            {
                user = new UserDto();
                user.FillNewUserFromModel(model, authModel);
            }
            else
            {
                user.FillUserFromModel(model, authModel);
            }

            //SetWatchlist(model, user, false);

            if (!SetUser(user))
            {
                throw new Exception("Could not save user to database!");
            }

            var loginAuth = _encryptionService.Encrypt(authModel);
            var loginUrl = _context.Request.GetHostUrl() + "/User/Auth?token=" + loginAuth;
            return _emailService.SendAuthenticationEmail(user, authModel, loginUrl);
        }
Beispiel #6
0
 public static UserDto FillUserFromModel(this UserModel model, UserDto user)
 {
     //user.Watchlist = model.Watchlist.Select(x => new WatchDto { Name = x }).ToList();
     return user;
 }