コード例 #1
0
        public ActionResult Password(string key)
        {
            using (var dataContext = new InnostarModelsContext())
            {
                var recoverRepository = new RecoverPasswordRequestRepository(dataContext);

                var requests = recoverRepository._Get(u => u.RequestKey.Equals(key) && u.IsActive).ToList();

                if (requests.Any())
                {
                    var request = requests.FirstOrDefault();

                    if (request == null)
                    {
                        throw new Exception("Данного запроса не существует");
                    }

                    var userRepository = new ChatUserRepository(dataContext);
                    var user           = userRepository._Get(e => e.Id == request.UserId).FirstOrDefault();

                    if (user == null)
                    {
                        throw new Exception("Произошла ошибка в обработке запроса. Обратитесь в службу поддержки");
                    }

                    return(View(new RecoverPasswordModel {
                        RequestId = request.Id, RequestKey = key, UserLogin = user.Login
                    }));
                }
                else
                {
                    return(RedirectToAction("NotFound", "Error"));
                }
            }
        }
コード例 #2
0
        public JsonResult _MessageVariables(string login)
        {
            var receiverStrings = login.Split('@');
            var xmppLogin       = receiverStrings[0];

            using (var context = new InnostarModelsContext())
            {
                var result = new Dictionary <string, string>();

                var repository = new ChatUserRepository(context);
                var users      = repository._Get(e => e.XmppLogin == xmppLogin).ToList();

                if (users.Any())
                {
                    var user  = users.FirstOrDefault();
                    var email = string.IsNullOrEmpty(user.Email) ? string.Empty : user.Email;
                    var name  = string.IsNullOrEmpty(user.Name) ? user.Login : user.Name;

                    result.Add("userEmail", email);
                    result.Add("userDisplayName", name);


                    var requestRepository = new RecoverPasswordRequestRepository(context);
                    var requests          =
                        requestRepository._Get(e => e.UserId == user.Id)
                        .OrderByDescending(e => e.RequestAcceptedTime)
                        .ToList();

                    var request = requests.Any() ? GetRecoverLink(requests.FirstOrDefault().RequestKey) : string.Empty;
                    result.Add("userPasswordRequest", request);

                    var confirmEmailRepository = new ConfirmEmailRequestRepository(context);
                    var confirmEmailrequests   =
                        confirmEmailRepository._Get(e => e.UserId == user.Id)
                        .OrderByDescending(e => e.RequestAcceptedTime)
                        .ToList();

                    var confirmEmailrequest = confirmEmailrequests.Any() ? GetConfirmLink(confirmEmailrequests.FirstOrDefault().RequestKey) : string.Empty;
                    result.Add("userConfirmRequest", confirmEmailrequest);
                }
                else
                {
                    result.Add("userEmail", string.Empty);
                    result.Add("userDisplayName", string.Empty);
                    result.Add("userRequest", string.Empty);
                }

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
コード例 #3
0
        public ActionResult Password(RecoverPasswordModel requestModel)
        {
            using (var dataContext = new InnostarModelsContext())
            {
                var recoverRepository = new RecoverPasswordRequestRepository(dataContext);

                var request = recoverRepository._Get(u => u.Id == requestModel.RequestId &&
                                                     u.RequestKey == requestModel.RequestKey &&
                                                     u.IsActive).FirstOrDefault();


                if (request == null)
                {
                    throw new Exception("Данного запроса не существует");
                }

                var userRepository = new ChatUserRepository(dataContext);
                var user           = userRepository._Get(e => e.Id == request.UserId).FirstOrDefault();

                if (user == null)
                {
                    throw new Exception("Произошла ошибка в обработке запроса. Обратитесь в службу поддержки");
                }

                if (!string.IsNullOrEmpty(requestModel.NewPassword))
                {
                    var pu = new PasswordUtility(requestModel.NewPassword.ToCharArray());
                    user.PasswordHash = pu.Hash;
                    user.PasswordSalt = pu.Salt;
                }

                userRepository._Update(user);
                userRepository._Save();

                //request.IsActive = false;
                //recoverRepository.Update(request);
                //recoverRepository.Save();

                return(RedirectToAction("Index", "Home"));
            }
        }