Exemplo n.º 1
0
 public IActionResult Register([FromForm] RegisterModel model)
 {
     ViewData["ServerName"] = Program.ServerName;
     ViewData["Title"]      = "注册";
     if (ModelState.IsValid)
     {
         if (model.VerificationCode == HttpContext.Session.GetString("VerificationCode"))
         {
             var time     = TimeWorker.GetTimeStamp10();
             var password = HashWorker.HashPassword(model.Password, time);
             db.Users.Add(new Users()
             {
                 Username          = model.Username,
                 Email             = model.Email,
                 Password          = password,
                 PreferredLanguage = "zh_CN",
                 CreateIp          = HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString(),
                 CreateTime        = time,
                 PermissionLevel   = 0,
                 IsEmailVerified   = 1
             });
             db.SaveChanges();
             return(RedirectToAction(actionName: "Index", controllerName: "User"));
         }
         else
         {
             ModelState.AddModelError(string.Empty, "验证码不正确!");
             return(View("Index", model));
         }
     }
     return(View("Index", model));
 }
Exemplo n.º 2
0
        /// <summary>
        /// 生成并保存RSA秘钥对
        /// </summary>
        public static void GenKey(MimirContext db)
        {
            RSACryptoServiceProvider key = new RSACryptoServiceProvider(4096);

            var publicKey  = RSACryptoServiceProviderExtensions.ToXmlString(key);
            var privateKey = RSACryptoServiceProviderExtensions.ToXmlString(key, true);

            foreach (var option in db.Options)
            {
                if (option.Option == "PublicKeyXml")
                {
                    option.Value = publicKey;
                }

                if (option.Option == "PrivateKeyXml")
                {
                    option.Value = privateKey;
                }

                if (option.Option == "PublicKey")
                {
                    option.Value = PublicKeyToJavaFormat(privateKey);
                }
            }
            db.SaveChanges();
        }
Exemplo n.º 3
0
        public IActionResult Create([FromForm] ProfileCreateModel model)
        {
            ViewData["ServerName"] = Program.ServerName;
            ViewData["Title"]      = "角色创建";

            if (ModelState.IsValid)
            {
                var user     = ByteConverter.ToObject <Users>(HttpContext.Session.Get("User"));
                var profiles = from p in db.Profiles where p.Uid == user.Id select p;
                if (profiles.Count() >= Program.MaxProfileCountPerUser)
                {
                    ModelState.AddModelError(string.Empty, "创建角色失败,角色数量已经达到上限!");
                    return(View(model));
                }
                else
                {
                    db.Profiles.Add(new Profiles()
                    {
                        Name       = model.Name,
                        Uuid       = UuidWorker.GetUuid(),
                        Uid        = user.Id,
                        SkinModel  = 0,
                        SkinUrl    = string.Empty,
                        CapeUrl    = string.Empty,
                        IsSelected = 0
                    });
                    db.SaveChanges();
                    ViewData["Result"] = "创建角色成功!";
                    return(View("Result"));
                }
            }
            else
            {
                return(View(model));
            }
        }