Beispiel #1
0
        public async Task <ActionResult> LoginPage(LoginUserModel loginUserModel)
        {
            if (ModelState.IsValid)
            {
                TokenContent rest = await _loginApiService.Authenticate(ApiUrl + "token", loginUserModel);

                if (rest.access_token != null)
                {
                    InstructorDto ınstructorDto = await _userApiService.Get(rest.access_token, ApiUrl + "api/User", loginUserModel);

                    string[] roles = new string[ınstructorDto.Roles.Count];
                    for (int i = 0; i < ınstructorDto.Roles.Count; i++)
                    {
                        ınstructorDto.Roles.ForEach(x => roles[i] = x.Name.ToString());
                    }


                    AuthenticationHelper.CreateAuthCookie(ınstructorDto.Id, ınstructorDto.UserName, DateTime.Now.AddDays(1), roles, false, ınstructorDto.FirstName, ınstructorDto.LastName);
                    //FormsAuthentication.SetAuthCookie(loginUserModel.Username, false);



                    Session["access_token"] = rest.access_token;
                    return(RedirectToAction("Index", "Home"));
                }

                ViewBag.LoginError = "Kullanıcı Adı ve paralo uyuşmamaktadır!";
            }

            return(View(loginUserModel));
        }
Beispiel #2
0
        internal bool EditNFTContent(string tokenSymbol, BigInteger tokenID, byte[] ram)
        {
            if (ram == null || ram.Length > TokenContent.MaxRAMSize)
            {
                return(false);
            }

            lock (_tokenContents)
            {
                if (_tokenContents.ContainsKey(tokenSymbol))
                {
                    var contents = _tokenContents[tokenSymbol];

                    if (contents.ContainsKey(tokenID))
                    {
                        var content = contents[tokenID];
                        if (ram == null)
                        {
                            ram = content.RAM;
                        }
                        content = new TokenContent(content.CurrentChain, content.CurrentOwner, content.ROM, ram, content.Value);
                        contents.Set(tokenID, content);
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #3
0
        internal BigInteger CreateNFT(string tokenSymbol, Address chainAddress, byte[] rom, byte[] ram, BigInteger value)
        {
            Throw.IfNull(rom, nameof(rom));
            Throw.IfNull(ram, nameof(ram));

            lock (_tokenContents)
            {
                KeyValueStore <BigInteger, TokenContent> contents;

                if (_tokenContents.ContainsKey(tokenSymbol))
                {
                    contents = _tokenContents[tokenSymbol];
                }
                else
                {
                    // NOTE here we specify the data size as small, meaning the total allowed size of a nft including rom + ram is 255 bytes
                    var key = "nft_" + tokenSymbol;
                    contents = new KeyValueStore <BigInteger, TokenContent>(this.CreateKeyStoreAdapter(key));
                    _tokenContents[tokenSymbol] = contents;
                }

                var tokenID = GenerateIDForNFT(tokenSymbol);

                var content = new TokenContent(chainAddress, chainAddress, rom, ram, value);
                contents[tokenID] = content;

                return(tokenID);
            }
        }
Beispiel #4
0
        internal BigInteger CreateNFT(Token token, Address chainAddress, Address ownerAddress, byte[] rom, byte[] ram)
        {
            lock (_tokenContents)
            {
                Dictionary <BigInteger, TokenContent> contents;

                if (_tokenContents.ContainsKey(token))
                {
                    contents = _tokenContents[token];
                }
                else
                {
                    contents = new Dictionary <BigInteger, TokenContent>();
                    _tokenContents[token] = contents;
                }

                var tokenID = token.GenerateID();

                var content = new TokenContent(rom, ram);
                content.CurrentChain = chainAddress;
                content.CurrentOwner = ownerAddress;
                contents[tokenID]    = content;

                return(tokenID);
            }
        }
Beispiel #5
0
        internal static async Task <string> CreateToken(User user)
        {
            var model = new TokenContent()
            {
                Email        = user.Email,
                PasswordHash = Sha256(user.PasswordHash)
            };
            var token = await CreateToken(model);

            return(token);
        }
Beispiel #6
0
        public async Task <TokenContent> Authenticate(string path, LoginUserModel loginUserModel)
        {
            var client  = new RestClient(path);
            var request = new RestRequest(Method.POST);

            request.AddHeader("cache-control", "no-cache");
            request.AddHeader("content-type", "application/x-www-form-urlencoded");
            request.AddParameter("application/x-www-form-urlencoded", $"grant_type=password&username={loginUserModel.Username}&password={loginUserModel.Password}", ParameterType.RequestBody);
            IRestResponse response     = client.Execute(request);
            TokenContent  tokenContent = JsonConvert.DeserializeObject <TokenContent>(response.Content);

            return(tokenContent);
        }
Beispiel #7
0
        internal static async Task <string> CreateToken(TokenContent content)
        {
            var key = await KeyClient.GetSecretAsync(WebConfigurationManager.AppSettings["SecretUri"]);

            var    keyBytes = Encoding.UTF8.GetBytes(key.Value);
            string token;

            try
            {
                token = JWT.Encode(content.ToDictionary(), keyBytes, JwsAlgorithm.HS256);
            }
            catch
            {
                token = null;
            }
            return(token);
        }
Beispiel #8
0
        private bool EditNFTLocation(string tokenSymbol, BigInteger tokenID, Address chainAddress, Address owner)
        {
            lock (_tokenContents)
            {
                if (_tokenContents.ContainsKey(tokenSymbol))
                {
                    var contents = _tokenContents[tokenSymbol];

                    if (contents.ContainsKey(tokenID))
                    {
                        var content = contents[tokenID];
                        content = new TokenContent(chainAddress, owner, content.ROM, content.RAM, content.Value);
                        contents.Set(tokenID, content);
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #9
0
        /// <summary>
        /// Attempts to refresh this token by checking the validity of its contents.
        /// If the content is not valid, null is returned.
        /// </summary>
        internal static async Task <string> RefreshToken(TokenContent model)
        {
            if (model.IsExpired())
            {
                model.UpdateExpiryTime();
            }
            else
            {
                var user = AccountController.GetUserFrom(model.Email);
                if (Sha256(user.PasswordHash) == model.PasswordHash)
                {
                    model.UpdateExpiryTime();
                }
                else
                {
                    return(null);
                }
            }
            var token = await CreateToken(model);

            return(token);
        }
        public async Task GetCostsTest()
        {
            DateTime from = new DateTime(2020, 1, 1);
            DateTime to   = new DateTime(2020, 12, 1);

            List <MonthCost> returnedList = new List <MonthCost>();

            PeriodCost periodMonth2 = new PeriodCost()
            {
                month = 2,
                year  = 2020
            };
            Cost bugsCostMonth2 = new Cost()
            {
                cant     = 100,
                unitCost = 2,
            };
            Cost usersCostMonth2 = new Cost()
            {
                cant     = 13,
                unitCost = 5,
            };
            PeriodCost periodMonth5 = new PeriodCost()
            {
                month = 5,
                year  = 2020
            };
            Cost bugsCostMonth5 = new Cost()
            {
                cant     = 167,
                unitCost = 4,
            };
            Cost usersCostMonth5 = new Cost()
            {
                cant     = 7,
                unitCost = 6,
            };

            MonthCost monthCost2 = new MonthCost()
            {
                id     = 1,
                bugs   = bugsCostMonth2,
                users  = usersCostMonth2,
                period = periodMonth2
            };
            MonthCost monthCost5 = new MonthCost()
            {
                id     = 2,
                bugs   = bugsCostMonth5,
                users  = usersCostMonth5,
                period = periodMonth5
            };

            returnedList.Add(monthCost2);
            returnedList.Add(monthCost5);

            var mockCostService = new Mock <ICostsService>();

            mockCostService.Setup(m => m.GetCosts(from, to, 1)).Returns(returnedList);

            var controller = new CostsController(
                mockCostService.Object,
                (new Mock <ILoggerManager>()).Object,
                (new Mock <IPingService>()).Object);

            controller.ControllerContext             = new ControllerContext();
            controller.ControllerContext.HttpContext = new DefaultHttpContext();

            User usr = new User()
            {
                id = 1, organizationId = 1
            };
            TokenContent tokenCont = new TokenContent()
            {
                user = usr, organizationId = 1
            };
            Token token = new Token()
            {
                exp = 10000, iat = 10000, data = tokenCont
            };

            controller.ControllerContext.HttpContext.Items["Token"] = token;

            var queryParam = new CostsFilterOptions()
            {
                From = from, To = to
            };

            var result = await controller.Get(queryParam);

            var okResult = result as OkObjectResult;

            List <MonthCost> model = okResult.Value as List <MonthCost>;

            mockCostService.VerifyAll();

            Assert.AreEqual(200, okResult.StatusCode);
            Assert.IsFalse(model == null);
            Assert.AreEqual(model.Count, 2);
        }
        /// <summary>
        /// This specifies the token items used by the conceptual topics.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="args"></param>
        protected void OnTokensItem(string keyword, XPathNavigator navigator)
        {
            if (_group == null)
            {
                throw new BuildException(
                          "There is not build group to provide the media/arts contents.");
            }

            BuildContext context = this.Context;

            BuildGroupContext groupContext = context.GroupContexts[_group.Id];

            if (groupContext == null)
            {
                throw new BuildException(
                          "The group context is not provided, and it is required by the build system.");
            }

            XmlWriter xmlWriter = navigator.InsertAfter();

            IList <TokenContent> listTokens = _group.TokenContents;

            if (listTokens == null || listTokens.Count == 0)
            {
                // Create an empty tokens file...
                string workingDir = context.WorkingDirectory;
                string tokenPath  = Path.Combine(workingDir, groupContext["$TokenFile"]);

                XmlWriterSettings settings = new XmlWriterSettings();
                settings.Indent             = true;
                settings.OmitXmlDeclaration = false;
                settings.Encoding           = Encoding.UTF8;
                using (XmlWriter tokenWriter = XmlWriter.Create(tokenPath, settings))
                {
                    tokenWriter.WriteStartElement("items");
                    tokenWriter.WriteAttributeString("xml", "space", String.Empty, "preserve");
                    tokenWriter.WriteAttributeString("xmlns", "ddue", String.Empty,
                                                     "http://ddue.schemas.microsoft.com/authoring/2003/5");
                    tokenWriter.WriteAttributeString("xmlns", "xlink", String.Empty,
                                                     "http://www.w3.org/1999/xlink");

                    tokenWriter.WriteComment(" There is no token items. ");

                    tokenWriter.WriteEndElement();
                }

                // <content file="%DXROOT%\Data\tokens.xml" />
                // For now, lets simply write the default...
                xmlWriter.WriteStartElement("content");
                xmlWriter.WriteAttributeString("file", tokenPath);
                xmlWriter.WriteEndElement();
            }
            else
            {
                int contentCount = listTokens.Count;
                for (int i = 0; i < contentCount; i++)
                {
                    TokenContent tokenContent = listTokens[i];
                    if (tokenContent == null || tokenContent.IsEmpty)
                    {
                        continue;
                    }
                    xmlWriter.WriteStartElement("content");
                    xmlWriter.WriteAttributeString("file", tokenContent.ContentFile);
                    xmlWriter.WriteEndElement();
                }
            }

            xmlWriter.Close();
            navigator.DeleteSelf();
        }