예제 #1
0
        public override void APIPost(Users newUser, AppDbContext context)
        {
            ErrInfLogger.LockInstance.InfoLog("APIPost launched." + _logInfo);

            SqlParameter result = new SqlParameter("@result", System.Data.SqlDbType.Int)
            {
                Direction = System.Data.ParameterDirection.Output
            };

            context.Database.ExecuteSqlCommand("SELECT @result = (NEXT VALUE FOR IntSeq)", result);

            //(int)result.Value
            ErrInfLogger.LockInstance.InfoLog(result.Value.ToString());

            newUser.Id                  = (int)result.Value;
            newUser.PermissionId        = 0;
            newUser.AuthToken           = _jwt.ReturnJWT(System.DateTime.Now, 0, (int)result.Value);
            newUser.AuthTokenExpiration = System.DateTime.Now;
            newUser.Salt                = SaltGenerator.GenerateSalt();
            newUser.UserAccountStatus   = "normal";

            // encrypt password
            newUser.HashPassword = _krypton.EncryptStringAES(newUser.HashPassword, newUser.Salt);
            context.Users.Add(newUser);

            context.SaveChanges();
        }