Example #1
0
        /// <summary>
        /// This constructor can only be used by ConcurrentMaltParserService
        /// </summary>
        /// <param name="_optionContainer"> a option container index </param>
        /// <param name="_mcoURL"> a URL to a valid MaltParser model file. </param>
        /// <exception cref="MaltChainedException"> </exception>
        internal ConcurrentMaltParserModel(int _optionContainer, Url _mcoURL)
        {
            var      optionContainer = _optionContainer;
            McoModel mcoModel        = new McoModel(_mcoURL);
            string   inputFormatName = OptionManager.instance().getOptionValue(optionContainer, "input", "format").ToString().Trim();
            Url      inputFormatURL  = null;

            try
            {
                inputFormatURL = mcoModel.GetMcoEntryUrl(inputFormatName);
            }
            catch (IOException e)
            {
                throw new MaltChainedException("Couldn't read file " + inputFormatName + " from mco-file ", e);
            }
            DataFormatManager dataFormatManager = new DataFormatManager(inputFormatURL, inputFormatURL);

            parentSymbolTableHandler = new HashSymbolTableHandler();
            DataFormatInstance dataFormatInstance = dataFormatManager.InputDataFormatSpec.createDataFormatInstance(parentSymbolTableHandler, OptionManager.instance().getOptionValueString(optionContainer, "singlemalt", "null_value"));

            try
            {
                parentSymbolTableHandler.load(mcoModel.GetInputStreamReader("symboltables.sym", "UTF-8"));
            }
            catch (IOException e)
            {
                throw new MaltChainedException("Couldn't read file symboltables.sym from mco-file ", e);
            }
            defaultRootLabel = OptionManager.instance().getOptionValue(optionContainer, "graph", "root_label").ToString().Trim();
            markingStrategy  = LWDeprojectivizer.getMarkingStrategyInt(OptionManager.instance().getOptionValue(optionContainer, "pproj", "marking_strategy").ToString().Trim());
            coveredRoot      = !OptionManager.instance().getOptionValue(optionContainer, "pproj", "covered_root").ToString().Trim().Equals("none", StringComparison.OrdinalIgnoreCase);

            FeatureModelManager featureModelManager = loadFeatureModelManager(optionContainer, mcoModel);

            singleMalt           = new LWSingleMalt(optionContainer, dataFormatInstance, mcoModel, null, featureModelManager);
            concurrentDataFormat = DataFormat.ParseDataFormatXmLfile(inputFormatURL);
        }
Example #2
0
        public async Task <IActionResult> RegisterUser([FromBody] NewUserInputModel model)
        {
            // search role
            var role = _roleManager.FindByIdAsync(model.RoleID).Result;

            var user = new AppUser
            {
                UserName       = model.UserName,
                Email          = model.Email,
                OrganizationID = model.OrgID,
                EmailConfirmed = false,
                PhoneNumber    = model.PhoneNumber
            };

            var result = await _userManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                // code for adding user to role
                await _userManager.AddToRoleAsync(user, role.Name);

                var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

                var uriBuilder = new UriBuilder(model.BaseUrl + "/confirm");
                var parameters = HttpUtility.ParseQueryString(string.Empty);
                parameters["userId"] = user.Id.ToString();
                parameters["code"]   = code;
                uriBuilder.Query     = parameters.ToString();

                Uri finalUrl = uriBuilder.Uri;

                AccountVerificationData verificationData = new AccountVerificationData
                {
                    UserName = model.UserName,
                    SiteName = _config.Value.SolutionName,
                    BaseUrl  = finalUrl.AbsoluteUri,
                    Title    = "APlus Account Verification",
                    SiteUrl  = _config.Value.BaseURL
                };

                await _emailSender.SendEmailAsync(model.Email, "APlus Account Verification", DataFormatManager.GetFormatedAccountVerificationEmailTemplate(verificationData, _hostingEnvironment.ContentRootPath + _templateParams.Value.AccountVerificationTemplate));

                return(Ok(new
                {
                    result = true,
                    message = ""
                }));
            }
            else
            {
                List <string> list = new List <string>();
                foreach (var error in result.Errors)
                {
                    list.Add(error.Description);
                }
                return(Ok(new
                {
                    result = false,
                    message = list
                }));
            }
        }
Example #3
0
        public async Task <IActionResult> SendPasswordResetLinkMobile([FromBody] ForgotPasswordReq model)
        {
            try
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    return(Ok(false));
                }

                var code = await _userManager.GeneratePasswordResetTokenAsync(user);

                code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));

                bool available = true;
                int  mCode     = 0;

                Random rnd = new Random();
                do
                {
                    mCode = rnd.Next(100000, 999999);
                    var isAvailable = _context.passwordResetTokens.Where(o => o.MobileCode == mCode.ToString()).FirstOrDefault();
                    available = isAvailable == null;
                } while (!available);


                //insert to database
                PasswordResetToken passwordResetToken = new PasswordResetToken
                {
                    UserID       = user.Id,
                    IsActive     = true,
                    RegistedDate = DateTime.Now,
                    MobileCode   = mCode.ToString(),
                    Token        = code
                };

                _context.passwordResetTokens.Add(passwordResetToken);
                _ = _context.SaveChangesAsync();

                ForgotEmailDataMobile forgotEmailData = new ForgotEmailDataMobile
                {
                    Company  = _config.Value.CompanyName,
                    Email    = model.Email,
                    code     = mCode.ToString(),
                    SiteName = _config.Value.SolutionName,
                    SiteUrl  = _config.Value.BaseURL
                };

                await _emailSender.SendEmailAsync(model.Email, "APlus Account Password Reset", DataFormatManager.GetFormatedForgotPasswordEmailTemplate(forgotEmailData, _hostingEnvironment.ContentRootPath + _templateParams.Value.ForgotPasswordMailTemplateMobile));

                return(Ok(true));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #4
0
        public async Task <IActionResult> SendPasswordResetLink([FromBody] ForgotPasswordReq model)
        {
            try
            {
                var user = await _userManager.FindByEmailAsync(model.Email);

                if (user == null || !(await _userManager.IsEmailConfirmedAsync(user)))
                {
                    return(NotFound("Email address is not registered or wrong email."));
                }

                var code = await _userManager.GeneratePasswordResetTokenAsync(user);

                code = WebEncoders.Base64UrlEncode(Encoding.UTF8.GetBytes(code));


                //insert to database
                PasswordResetToken passwordResetToken = new PasswordResetToken
                {
                    UserID       = user.Id,
                    IsActive     = true,
                    RegistedDate = DateTime.Now,
                    Token        = code
                };

                _context.passwordResetTokens.Add(passwordResetToken);
                _ = _context.SaveChangesAsync();

                ForgotEmailData forgotEmailData = new ForgotEmailData
                {
                    Company          = _config.Value.CompanyName,
                    Email            = model.Email,
                    PasswordResetUrl = _config.Value.ResetEmailUrl + "?token=" + code,
                    SiteName         = _config.Value.SolutionName,
                    SiteUrl          = _config.Value.BaseURL
                };

                await _emailSender.SendEmailAsync(model.Email, "APlus Account Password Reset", DataFormatManager.GetFormatedForgotPasswordEmailTemplate(forgotEmailData, _hostingEnvironment.ContentRootPath + _templateParams.Value.ForgotPasswordMailTemplate));

                return(Ok("Email sent successfully"));
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Example #5
0
 /// <summary>
 /// A String formatter method which is localized by global data format.
 /// </summary>
 /// <param name="o">Object to format.</param>
 /// <param name="dataFormatType">Globalized data format.</param>
 /// <returns></returns>
 public static string ToString(this object o, DataFormatType dataFormatType)
 {
     return(DataFormatManager.FormatToString(o, dataFormatType));
 }