示例#1
0
        private string GetURL(User user, string tokenName, string controlName, string routeNameValue)
        {
            string url        = string.Empty;
            string websiteURL = _siteInformationSettings.SiteURL;

            try
            {
                var    userAttribute  = _genericAttributeService.GetAttributesForEntityByToken(user.Id, nameof(user), tokenName).OrderByDescending(x => x.Id).FirstOrDefault();
                string attributeValue = userAttribute != null ? userAttribute.Value : string.Empty;
                url = RouteUrl(routeName: routeNameValue, controlName: controlName, routeValues: new { token = attributeValue, email = user.Email });
            }
            catch (Exception exc)
            {
                //log error
                var logger = EngineContext.Current.Resolve <ILogger>();
                //we put in to nested try-catch to prevent possible cyclic (if some error occurs)
                try
                {
                    logger.Error(exc.Message, exc);
                }
                catch (Exception)
                {
                    //do nothing
                }
            }
            return($"{websiteURL.TrimEnd('/')}{url}");
            //return url;
        }
示例#2
0
        public virtual IActionResult AccountActivation(string token, string email)
        {
            var user = _userService.GetUserByEmail(email);

            if (user == null)
            {
                return(RedirectToAction("Login", "User"));
            }

            var userAccountActivationAttribute = _genericAttributeService.GetAttributesForEntityByToken(user.Id, nameof(user), ResearchUserDefaults.AccountActivationTokenAttribute)
                                                 .Where(x => x.Value.Contains(token)).FirstOrDefault();
            string cToken     = userAccountActivationAttribute != null ? userAccountActivationAttribute.Value : string.Empty;
            var    researcher = _researcherService.GetResearcherByEmail(email);

            if (researcher.IsCompleted)
            {
                return
                    (View(new AccountActivationModel
                {
                    Result = "ระบบยืนยันอีเมลของเท่านเรียบร้อยแล้ว โปรดล็อคอินเข้าสู่ระบบ !"
                }));
            }

            //if (!cToken.Equals(token, StringComparison.InvariantCultureIgnoreCase))
            if (string.IsNullOrEmpty(cToken))
            {
                return(RedirectToAction("Login", "User"));
            }

            //activate researcher account
            researcher.IsCompleted = true;
            researcher.Modified    = DateTime.UtcNow;
            _researcherService.UpdateResearcher(researcher);
            user.Modified = DateTime.UtcNow;
            _userService.UpdateUser(user);
            _genericAttributeService.SaveAttribute(user, ResearchUserDefaults.AccountActivationTokenAttribute, "");

            //send welcome message
            _workflowMessageService.SendUserWelcomeMessage(user, 0);

            var model = new AccountActivationModel
            {
                Result = "ยินดีต้อนรับเข้าสู่ระบบสารสนเทศเพื่อการบริหารงานวิจัย ระบบได้ยืนยันอีเมลของเท่าน โปรดล็อคอินเข้าสู่ระบบ !"
            };

            return(View(model));
        }