Пример #1
0
        public string Confirm()
        {
            string query  = Request.RequestUri.ParseQueryString().Get("id");
            string email  = AesConfig.DecryptStringFromBytes_Aes(AccessTokenValidator.StringToByteArray(query));
            var    dbUser = (from m in db.Users
                             where m.Email == email
                             select m).FirstOrDefault();

            dbUser.Confirmed = 1;
            db.SaveChanges();
            return("You have successfully activated yout account");
        }
Пример #2
0
        public TokenString Login([FromBody] LoginInfo user)
        {
            var dbUser = (from m in db.Users
                          where m.Email == user.Email
                          select m).First();
            TokenString token = new TokenString();

            token.Token = "invalid";
            if (PasswordHash.ValidatePassword(user.Password, dbUser.Password) && dbUser.Confirmed == 1)
            {
                token.Token = BitConverter.ToString(AesConfig.EncryptStringToBytes_Aes(user.Email)).Replace("-", string.Empty);
                //token.Token= Convert.ToBase64String(AesConfig.EncryptStringToBytes_Aes(user.Email));
            }
            return(token);
        }
Пример #3
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            NetworkingConfig networkingConfig = this.Configuration.GetSection("Networking").Get <NetworkingConfig>();

            services.Configure <ForwardedHeadersOptions>(options =>
            {
                options.ForwardLimit = networkingConfig.UpstreamProxyHops;

                if (networkingConfig.KnownProxyServers?.Count > 0)
                {
                    foreach (string ip in networkingConfig.KnownProxyServers)
                    {
                        options.KnownProxies.Add(IPAddress.Parse(ip));
                    }
                }
            });

            string    redisConString = this.Configuration.GetValue <string>("RedisConnectionString");
            AesConfig aesSettings    = this.Configuration.GetSection("AesSettings").Get <AesConfig>();

            services.AddSingleton <IConnectionMultiplexer>(_ =>
                                                           ConnectionMultiplexer.Connect(redisConString));

            services.AddTransient <IDatabase>(sp => sp
                                              .GetRequiredService <IConnectionMultiplexer>()
                                              .GetDatabase(0));
            services.AddTransient <IClock>(s => SystemClock.Instance);
            services.AddTransient <ICryptoService, CryptoService>();

            services.AddTransient <IAesEncryptionService>(s => new AesEncryptionService(aesSettings.MasterKey, aesSettings.Version));

            services
            .AddMvc()
            .AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.IgnoreNullValues     = true;
                options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;

                // TODO: figure out NodaTime in 3.0
            });

            services
            .AddHealthChecks()
            .AddCheck <VersionHealthCheck>("version_health_check")
            .AddCheck <RedisHealthCheck>("redis_health_check");
        }
Пример #4
0
        public string Create([FromBody] User value)
        {
            value.Confirmed = 0;
            value.Password  = PasswordHash.CreateHash(value.Password);
            db.Users.Add(value);
            string id   = BitConverter.ToString(AesConfig.EncryptStringToBytes_Aes(value.Email)).Replace("-", string.Empty);
            string link = "https://pkg.apphb.com/#confirm=" + id;

            try
            {
                Mailer.Mailer.SendMail(value.Email, "PKG Registration", "You have been successfully registered to this PKG, in order to start using your key, you need to activate your account first. To do so click this [link](" + link + ")");
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            db.SaveChanges();
            return("User successfully created");
        }